如何从tkinter Python中的框架类重新运行init
这是我的代码-(删除了很多东西以简化它)
class HeadlineGame(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.container = container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
self.show_frame(StartPage)
moneylabel =tk.Label(self, text="Money: " + str(money))
def show_frame(self, controller):
if controller not in self.frames:
self.frames[controller] = frame = controller(self.container, self)
frame.grid(row=0, column=0, sticky="nsew")
frame = self.frames[controller]
frame.tkraise()
q = 0
y = 0
def multifunction(*args):
for function in args:
function
def publishwindow():
global q
q = 0
def publisharticleimplement():
pass
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
q = 0
while q==0:
print(money)
q = 1
publishimg = tk.PhotoImage(file="assets/publishbutton.png")
cb = lambda: multifunction(controller.show_frame(PublishPage), publishwindow())
publishbutton = tk.Button(self, image=publishimg, borderwidth=0, command= cb)
publishbutton.image = publishimg
publishbutton.place(x=503, y=315)
moneylabel =tk.Label(self, text="Money: " + str(money))
moneylabel.place(x=0, y=360)
class PublishPage(tk.Frame):
def __init__(self, parent, controller):
global money
tk.Frame.__init__(self, parent)
fakelogo = tk.PhotoImage(file="assets/fakenewslogo.png")
publishimg = tk.PhotoImage(file="assets/publishbutton.png")
moneylabel =tk.Label(self, text="Money: " + str(money))
moneylabel.place(x=0, y=360)
def fakechoice():
print('xyz')
cb = lambda: multifunction(controller.show_frame(StartPage), publisharticleimplement())
publisharticle = tk.Button(self, image=publishimg, borderwidth=0, command=cb)
publisharticle.image = publishimg
publisharticle.place(x=503, y=380)
fakechoice()
我想要的是从类Startpage框架中重新运行init,以便它更新整个框架并重新运行整个代码和while循环
通过在publisharticleimplement函数中输入代码,从StartPage重新运行definit,是否可以实现这一点
任何解决方案都将不胜感激
目前没有回答
相关问题 更多 >
编程相关推荐