如何使用checkbutton我禁用条目...我得到这个,但它好好尝试工作(蟒蛇2.7.1)...使用checkbutton禁用小部件?
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
from Tkinter import *
root = Tk()
class Principal(tk.Tk):
def __init__(self, *args, **kwargs):
foo = ""
nac = ""
global ck1
nac = IntVar()
ck1 = Checkbutton(root, text='Test',variable=nac, command=self.naccheck)
ck1.pack()
global ent
ent = Entry(root, width = 20, background = 'white', textvariable = foo, state = DISABLED)
ent.pack()
def naccheck(self):
if nac == 1:
ent.configure(state='disabled')
else:
ent.configure(state='normal')
app=Principal()
root.mainloop()
谢谢...我使用“Tkinter作为tk”因为我喜欢一些旧样式的小部件(而不是ttk)... – Hairo 2011-05-26 14:32:19
@Hairo:我不明白你的意见。如何导入不会影响您是否使用ttk或原始小部件。另外,你说你正在使用'import Tkinter as tk',但在你的例子中显然你不是。你的例子显示'从Tkinter导入*' – 2011-05-26 15:16:32
ohh,对不起,这只是一个例子......在我使用“import Tkinter as tk”的代码中,所以如果我添加“tk.Entry”得到旧样式,并且if只需使用“Entry”即可获得ttk风格... – Hairo 2011-05-26 16:59:29