python - 单击两个按钮时如何调用函数python
问题描述
我正在尝试在 python 中创建一些东西。我是python新手。我有这些框架,当单击一个特殊按钮时,每个框架都会打开。帧一个接一个地打开。我想在单击第一帧的按钮 1 和第二帧的按钮 1 时打开最后一页。谁能帮我?这是他的代码:
import tkinter as tk
LARGE_FONT="Verdana",16,"Bold"
MEDIUM_FONT="Verdana Bold"
class SeaofBTCapp(tk.Tk):
def __init__(self,*args,**kwargs):
tk.Tk.__init__(self)
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,firstPage,secondPage, thirdPage,):
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()
def qf(param):
print(param)
class StartPage(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
button1=tk.Button(self,text="START",
command=lambda : controller.show_frame(firstPage))
button1.pack()
def OnButtonClick( button_id):
if (button_id == 11 and button_id==21):
#if button 11 and 21 were clicked I want to show the final page frame not thiird page frame
class firstPage(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
label1=tk.Label(self,width=50,text="Label one:",bg="#362458",fg="#FFFFFF")
label1.grid(row=2,pady=10,padx=10)
button1=tk.Button(self,text="Button 1",width=8,bg="#362458",fg="#FFFFFF",borderwidth=2, relief="solid",
command=lambda : [controller.show_frame(secondPage),OnButtonClick(11)])
button1.grid(row=4,pady=10,padx=10)
button2=tk.Button(self,text="Button 2",width=8,bg="#362458",fg="#FFFFFF",borderwidth=2, relief="solid",
command=lambda : [controller.show_frame(secondPage),OnButtonClick(12)])
button2.grid(row=6,pady=10,padx=10)
class secondPage(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
label1=tk.Label(self,width=50,text="Label 2",bg="#362458",fg="#FFFFFF")
label1.grid(row=2,pady=10,padx=10)
button1=tk.Button(self,text="Button 1",width=8,bg="#362458",fg="#FFFFFF",borderwidth=2, relief="solid",
command=lambda : [controller.show_frame(thirdPage),OnButtonClick(21)])
button1.grid(row=4,pady=10,padx=10)
button2=tk.Button(self,text="Button 2",width=8,bg="#362458",fg="#FFFFFF",borderwidth=2, relief="solid",
command=lambda : [controller.show_frame(thirdPage),OnButtonClick(22)])
button2.grid(row=6,pady=10,padx=10)
class thirdPage(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
label1=tk.Label(self,width=50,text="Label 3",bg="#362458",fg="#FFFFFF")
label1.grid(row=2,pady=10,padx=10)
button1=tk.Button(self,text="Button 1",width=8,bg="#362458",fg="#FFFFFF",borderwidth=2, relief="solid",
command=lambda : [controller.show_frame(FinalPage),OnButtonClick(31)])
button1.grid(row=4,pady=10,padx=10)
button2=tk.Button(self,text="Button 2",width=8,bg="#362458",fg="#FFFFFF",borderwidth=2, relief="solid",
command=lambda : [controller.show_frame(FinalPage),OnButtonClick(32)])
button2.grid(row=6,pady=10,padx=10
class FinalPage(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
button1=tk.Button(self,text="Click here to go to the start page",bg="#00BF89",fg="white",
command=lambda : controller.show_frame(StartPage))
button1.pack()
app=SeaofBTCapp()
app.mainloop()
解决方案
推荐阅读
- reactjs - 将 JS 路由反应到具有过滤数据的相同组件
- c++ - 将 Qt 与 Visual Studio 代码一起使用 (Windows)
- php - Laravel 为 auth 和 guest 用户路由不同的控制器
- java - hibernate一对多映射中各种子表的插入顺序
- javascript - 使用 AXIOS 和 VueJs 用二维数组映射数据
- javascript - 如何在请求后保存变量的值,但在第一次加载时有不同的值?
- python - jinja2.exceptions.TemplateNotFound 为什么会不断弹出?
- javascript - 如何使用 JavaScript 替换文本的多个实例?
- javascript - 如何将具有像现在 + 1 天这样的日期计算的字符串解析为日期对象?
- node.js - Nodemailer和Godaddy,我尝试了所有解决方案都无济于事