自己最近在捯饬一些tkinter的东西,有个东西很困惑。为什么单独的一个窗口可以实现command
,加了一个窗口之后就不灵了。。。不知道是哪里影响到了,给出代码
on_hit = False
class QD:
def window_info(self):
info = tk.Tk()
info.title('补签界面')
info.geometry('250x150')
# label-补签的学生学号
label_info = tk.Label(info, text="输入补签的学生学号: ", font=('宋体', 10), height='1')
label_info.place(x=35, y=20, anchor='nw')
# entry-请输入学生学号
entry_info = tk.Entry(info)
entry_info.place(x=35, y=50, width="180", anchor='nw')
var = tk.StringVar()
label_tip = tk.Label(info, textvariable=var, font=('等线', 10))
label_tip.place(x=50, y=115, anchor='nw')
def click_sure():
global on_hit
if not on_hit:
on_hit = True
var.set('补签成功!请关闭窗口!')
else:
on_hit = False
var.set('')
button_sure = tk.Button(info, text='确定', width=15, height=1, command=click_sure)
button_sure.place(x=70, y=80, anchor='nw')
info.mainloop()
window = QD()
window.window_info()
测试是可以显示出label-tip

然而加上一个窗口就触发不了了:
on_hit = False
class QD:
def window_begin(self):
begin = tk.Tk()
begin.title('课堂点名器 3.0--开始点名界面')
begin.geometry('500x300')
# text-输出各种名单
text_list = tk.Text(begin, height="18")
text_list.pack()
# button-补签
def click_arrive():
self.window_info()
button_arrive = tk.Button(begin, text='补签', width=15, height=1, command=click_arrive)
button_arrive.place(x=180, y=250, anchor='nw')
# 返回
def callback():
if messagebox.askokcancel("退出", "是否退出点名环节?"):
begin.destroy()
begin.protocol("WM_DELETE_WINDOW", callback)
begin.mainloop()
def window_info(self):
info = tk.Tk()
info.title('补签界面')
info.geometry('250x150')
# label-补签的学生学号
label_info = tk.Label(info, text="输入补签的学生学号: ", font=('宋体', 10), height='1')
label_info.place(x=35, y=20, anchor='nw')
# entry-请输入学生学号
entry_info = tk.Entry(info)
entry_info.place(x=35, y=50, width="180", anchor='nw')
var = tk.StringVar()
label_tip = tk.Label(info, textvariable=var, font=('等线', 10))
label_tip.place(x=50, y=115, anchor='nw')
def click_sure():
global on_hit
if not on_hit:
on_hit = True
var.set('补签成功!请关闭窗口!')
else:
on_hit = False
var.set('')
button_sure = tk.Button(info, text='确定', width=15, height=1, command=click_sure)
button_sure.place(x=70, y=80, anchor='nw')
info.mainloop()
window = QD()
window.window_begin()
然后。。。。点击按钮就显示不出来了。。。。= =,到底是因为什么问题。。。
