【发布时间】:2021-02-23 09:24:50
【问题描述】:
我有一个主脚本。当您按下按钮(在 tkinter 中)时,您将打开一个带有新窗口和新按钮的类。 当您单击新按钮(在新窗口和不同文件中)时,主窗口中的文本应该会更新。
我有以下几点:
主脚本
from tkinter import *
from kandit import Kandit
root=Tk()
def hoop():
s=Kandit()
label.configure(text=s)
button=Button(root, text="ok", command=hoop)
button.grid(row=0,column=0)
label=Label(root, text="nog niet dus")
label.grid(row=1, column=0)
子脚本
class Kandit:
def __init__(self):
self.Master=Toplevel()
self.Button=Button(self.Master, text="check", command=self.Return())
self.Button.grid(row=0,column=0)
self.Master.mainloop()
def Return(self):
self.Keuze="nothing"
return self.Keuze #, self.Master.destroy()
除了销毁之外,它一直有效,直到我按下“检查”按钮。 比什么都没有发生。
【问题讨论】:
-
首先你写了
self.Button = Button(..., command=self.Return()),我想你想写self.Button = Button(..., command=self.Return)。
标签: python function tkinter button