我对python 3.6比较陌生。我能够更改frame1中按钮的状态,但不能更改frame2中的按钮状态,就好像frame2中的对象位于不同的命名空间中一样。或者是吗?有人请帮忙吗?这是代码:
from tkinter import *
class Raffle():
def __init__(self, master):
self.master = master
master.geometry("280x72")
frame1 = Frame(master, height=1, background="steelblue")
frame2 = Frame(master, height=1, background="powderblue")
self.btnGet = Button(frame1, text="Get Entry", bg="slategray",
fg="whitesmoke", command=self.cmd1)
self.btnGet.pack(side=LEFT, padx=5, pady=5)
self.btnEnum = Button(frame1, text="Break Down", bg="slategray",
fg="whitesmoke", state="disabled", command=self.cmd2)
self.btnEnum.pack(side=LEFT, padx=5)
self.shuf = Button(frame1, text="Shuffle", bg="slategray",
fg="whitesmoke", state="disabled", command=self.cmd3)
self.shuf.pack(side=LEFT, padx=5)
self.quickWin = Button(frame1, text="Winners", bg="slategray",
fg="whitesmoke", state="disabled", command=self.cmd4)
self.quickWin.pack(side=LEFT)
self.reset = Button(frame2, text="Reset", bg="slategray",
fg="whitesmoke", command=self.cmd5)
self.reset.pack(side=RIGHT, padx=10)
self.Draw = Button(frame2, text="Draw",
bg="magenta", fg="yellow", state="disabled",
command=self.cmd6).pack(side=RIGHT, pady=5)
frame1.pack(side=TOP, expand=NO, fill=X)
frame2.pack(side=TOP, expand=NO, fill=X)
def cmd1(self):
self.btnEnum.configure({"state": "normal"})
def cmd2(self):
ab={self.btnGet:0,
self.btnEnum:0,
self.shuf:1,
self.quickWin:1}
#self.draw:1}
self.able(ab)
def cmd3(self):
pass
def cmd4(self):
pass
def cmd5(self):
ab={self.btnGet:1,
self.btnEnum:0,
self.shuf:0,
self.quickWin:0}
#self.draw:0}
self.able(ab)
def cmd6(self):
pass
def able(self, dic):
for widget in dic:
if dic[widget]==0:
widget.configure({"state": "disabled"}) #disables entry
else:
widget.configure({"state": "normal"}) #enables entry
if __name__ == '__main__':
parent = Tk()
app = Raffle(parent)
parent.mainloop()
frame1中的按钮很好,但不是frame2中的'draw'按钮,我无法启用或禁用。我评论了指向该按钮(绘图)的部分,因为它将错误作为“NonType”对象返回。请有人帮忙......
答案 0 :(得分:0)
呼!毕竟这是一个简单的解决方案。我只需将它装在另一条线上。
self.Draw = Button(frame2, text="Draw",
bg="magenta", fg="yellow", state="disabled", command=self.cmd6)
self.draw.pack(side=RIGHT, pady=5)