python中button按钮的状态不包括_python-如何在不使用按钮命令的情况下使用...

我目前正在使用一个GUI,我希望我的GUI在最后一帧停留5秒,然后从最后一帧返回到第一帧而没有任何交互.

如果我使用after小部件方法,则计时器将从应用程序的开头开始.

如果将其放在方法中,并且调用该方法,则会发生相同的行为.另一方面,如果我通过按钮调用该函数,它将按预期工作.

调节器

# The code for changing pages was derived from:

https://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter

# License: http://creativecommons.org/licenses/by-sa/3.0/

import tkinter as tk

LARGE_FONT= ("Verdana", 12)

class SeaofBTCapp(tk.Tk):

def __init__(self, *args, **kwargs):

tk.Tk.__init__(self, *args, **kwargs)

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 = {}

for F in (StartPage, PageOne, PageTwo):

frame = F(container, self)

self.frames[F] = frame

frame.grid(row=0, column=0, sticky="nsew")

self.show_frame(StartPage)

def show_frame(self, cont):

frame = self.frames[cont]

frame.tkraise()

StartPage类

class StartPage(tk.Frame):

def __init__(self, parent, controller):

tk.Frame.__init__(self,parent)

label = tk.Label(self, text="Start Page", font=LARGE_FONT)

label.pack(pady=10,padx=10)

button = tk.Button(self, text="Visit Page 1",

command=lambda: controller.show_frame(PageOne))

button.pack()

button2 = tk.Button(self, text="Visit Page 2",

command=lambda: controller.show_frame(PageTwo))

button2.pack()

PageOne类

class PageOne(tk.Frame):

def __init__(self, parent, controller):

tk.Frame.__init__(self, parent)

label = tk.Label(self, text="Page One!!!", font=LARGE_FONT)

label.pack(pady=10,padx=10)

button1 = tk.Button(self, text="Back to Home",

command=lambda: controller.show_frame(StartPage))

button1.pack()

button2 = tk.Button(self, text="Page Two",

command=lambda: controller.show_frame(PageTwo))

button2.pack()

PageTwo类

class PageTwo(tk.Frame):

def __init__(self, parent, controller):

tk.Frame.__init__(self, parent)

label = tk.Label(self, text="Page Two!!!", font=LARGE_FONT)

label.pack(pady=10,padx=10)

button1 = tk.Button(self, text="Back to Home",

command=lambda:self.start_reset())

button1.pack()

button2 = tk.Button(self, text="Page One",

command=lambda: controller.show_frame(PageOne))

button2.pack()

# self.after(5000,self.controller.show_frame(StartPage)) works only

# once and the time starts from the start of the GUI and after 5000ms it takes

# the gui to the start page no matter what

def start_reset(self):

self.after(5000,self.controller.show_frame(StartPage))

app = SeaofBTCapp()

app.mainloop()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值