【发布时间】:2017-06-29 22:12:57
【问题描述】:
Mac OSX Sierra 上的 Python 2.7 Tkinter 8.5
我正在关注这个Tkinter documentation 并尝试不同的小部件,但在使用文档中描述的结果使复选按钮闪烁时遇到了一些困难。
我已经让“self.newButton”正确调用了“makeCheckbuttonFlash”并打印了消息,但没有看到检查按钮有任何变化。
注意:在下面的代码中,我丢失了方法选项卡上的格式 - 不知道如何修复
import Tkinter as tk
class Server(tk.Frame):
def __init__(self, master = None):
tk.Frame.__init__(self, master)
self.grid(sticky = tk.N + tk.S + tk.E + tk.W)
self.createWidgets()
def createWidgets(self):
top = self.winfo_toplevel()
top.rowconfigure(0, weight = 1)
top.columnconfigure(0, weight = 1)
self.rowconfigure(0, weight = 1)
self.columnconfigure(0, weight = 1)
self.quitButton = tk.Button(self, text = "Quit", command = self.quit)
self.quitButton.grid(row = 0, column = 0, sticky = tk.N + tk.S)
self.newButton = tk.Button(self, text = "New", command = self.makeCheckButtonFlash)
self.newButton.grid(row = 0, column = 1, sticky = tk.N + tk.S)
self.checkButton = tk.Checkbutton(self, text = "Check Button", activeforeground = "red")
self.checkButton.grid(row = 1, column = 0)
def makeCheckButtonFlash(self):
print "makeCheckButtonFlash"
self.checkButton.flash()
app = Server()
app.master.title("Server")
app.mainloop()
【问题讨论】:
-
您可以通过使用空格而不是制表符来解决制表符问题。请花时间修复它。