【发布时间】:2021-05-06 21:16:33
【问题描述】:
好的,所以我正在尝试制作工具提示,自从我尝试制作测试工具提示后,我尝试将其绑定到的下拉框出现错误。 我试过给它列表以外的字符串。 我对这些东西很陌生,所以我不知道这里发生了什么。
#Here I import tKinter to allow myself to create a UI
from tkinter import *
from tkinter.tix import *
#This code creates the window.
root = Tk()
#This is a list of options for your government's control over the economy of your nation
econcontrol = ["Laissez Faire", "Some Government Intervention", "State Capitalism", "Planned Economy"]
econlaw = StringVar()
econlaw.set(econcontrol[0])
#Drop down box
dropdown = OptionMenu(root, econlaw, econcontrol)
dropdown.pack()
#tooltip
tip = Balloon(root)
#bind tooltip to thing
tip.bind_widget(dropdown, balloonmsg="Hello?")
#This code makes the window stay up.
root.mainloop()
【问题讨论】:
-
请edit您的问题包括调试细节。这是一个有用的question checklist
-
这也许是为什么不使用
from x import *的一个例子。 -
正确的调用是
OptionMenu(root, econlaw, *econcontrol),尽管我没有立即看到给定错误消息的来源。OptionMenu期望容器、变量、初始值和任何附加值都作为单独的参数。*econcontrol单独在这里起作用,因为econcontrol的第一个元素也是最初选择的值。 -
更具体地说,错误消息来自
tkinter.tix.OptionMenu,而不是tkinter.OptionMenu,您正在用另一个导入语句覆盖一个导入语句。