【发布时间】:2018-05-17 00:08:28
【问题描述】:
这是我的 GUI 程序的一部分,我遇到了问题,希望有人能帮助我。我想要做的是,当您单击检查按钮时,它应该在文本小部件上显示价格但是当我单击检查按钮时它给了我一个错误:
文件“E:\Phython\Theater.py”,第 147 行,在 update_text 中 如果 self.matinee_price.get(): AttributeError: 'Checkbutton' 对象没有属性 'get'
def matinee_pricing(self):
#Purchase Label
self.theater_label = tkinter.Label(text='Purchase Theater Seats Here', font=('Verdana', 15, 'bold'))
self.theater_label.grid(row=2, column=10)
#Checkbutton
self.matinee_price = BooleanVar()
self.matinee_price = tkinter.Checkbutton(text = '101 \nthru \n105', font=('Verdana', 10), bg='light pink', height=5, width=10,\
variable = self.matinee_price, command = self.update_text)
self.matinee_price.grid(row=5, column=9)
self.result = tkinter.Text(width=10, height=1, wrap = WORD)
self.result.grid(row=20, column=10)
def update_text(self):
price = ''
if self.matinee_price.get():
price += '$50'
self.result.delete(0.0, END)
self.result.insert(0.0, price)
【问题讨论】:
-
你真的不应该像那样两次导入 tkinter,这是不好的做法。请参阅this 了解更多信息。
标签: python user-interface tkinter