|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
大佬帮忙看看这个tk为什么不显示GUI
from tkinter import *
from tkinter import messagebox
class Application(Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.createWiget()
def createWiget(self):
self.codeHobby = IntVar()
self.videoHobby = IntVar()
print(self.codeHobby.get())
self.c1 = Checkbutton(self, text='敲代码', onvalue=1, offvalue=0)
self.c2 = Checkbutton(self, text='看电视', onvalue=1, offvalue=0)
self.c1.pack(side='left')
self.c2.pack(side='left')
Button(self, text='确定', command=self.confirm, ).pack()
def confirm(self):
if self.videoHobby.get() == 1:
messagebox.showinfo('看电视', '正经人都看电视')
if self.codeHobby.get() == 1:
messagebox.showinfo('敲代码', '正经人谁敲代码啊')
if __name__ == '__main__':
root = Tk()
root.geometry('800x500+500+200')
root.title('checkbutton')
app = Application(master=root)
因为交互模式你不关闭shell 程序都没结束呀,所以窗口还在,
而你直接文本模式运行程序执行完就结束了,因为结束的太快所以你看不到窗口,想要他不结束的话加上 root.mainloop()
from tkinter import *
from tkinter import messagebox
class Application(Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.createWiget()
def createWiget(self):
self.codeHobby = IntVar()
self.videoHobby = IntVar()
print(self.codeHobby.get())
self.c1 = Checkbutton(self, text='敲代码', onvalue=1, offvalue=0)
self.c2 = Checkbutton(self, text='看电视', onvalue=1, offvalue=0)
self.c1.pack(side='left')
self.c2.pack(side='left')
Button(self, text='确定', command=self.confirm, ).pack()
def confirm(self):
if self.videoHobby.get() == 1:
messagebox.showinfo('看电视', '正经人都看电视')
if self.codeHobby.get() == 1:
messagebox.showinfo('敲代码', '正经人谁敲代码啊')
if __name__ == '__main__':
root = Tk()
root.geometry('800x500+500+200')
root.title('checkbutton')
app = Application(master=root)
root.mainloop() # 加上这一行
|
|