tkinter python从yes msg框打开框架

时间:2015-04-18 11:51:57

标签: python tkinter

编辑并改写为更清晰,更容易查看。 我只提取了这部分代码。 如果按下打开的zs页面,框架zs将打开。当我在按下打开信息时打开的对话框中按是,我想实现相同的功能

提前谢谢

代码:

import tkMessageBox
import Tkinter as tk
from Tkinter import *
from functools import partial

LARGE_FONT= ("Verdana", 12)

class ChangePages(tk.Tk):

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

        tk.Tk.__init__(self, *args, **kwargs)
        container = tk.Frame(self)
        container.pack()
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)
        self.frames = {}
        for F in (MainPage, PageZS):

            frame = F(container, self)

            self.frames[F] = frame

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

        self.show_frame(MainPage)

    def show_frame(self, cont):

        frame = self.frames[cont]
        frame.tkraise()

#MainPage
class MainPage(tk.Frame):

    def __init__(self, parent, controller):

        tk.Frame.__init__(self,parent)
        def C(*args): return partial(self.option_changed, *args)

        f = Frame(self)
        f.pack(side='top')

        def zsmessage():

            result = tkMessageBox.askquestion('Open page ZS', 'Do you want open page ZS ?', icon='warning')

            if result == 'yes':
                print 'Open page ZS'
                self.command=lambda: controller.show_frame(PageZS)
            else:
                print 'NO'

        btnzs = Button(f,text='Open MSG',fg='blue',font=('Helvetica',26),height=1, width=25,command=zsmessage)
        btnzs.grid(row=2,column=1)

        btnzsold=Button(f,text='Open Page ZS',fg='blue',font=('Helvetica',26),height=1, width=25,command=lambda: controller.show_frame(PageZS))
        btnzsold.grid(row=2,column=5)

class PageZS(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        f = Frame(self)
        f.pack(side='left')


        labelspacing=Label(f,text='PAGE ZS',fg='red',font=("Arial", 12, "bold"),width=15,height=0,relief='groove').grid(row=0,column=0)


app = ChangePages()
app.geometry('1000x500+0+0')
app.title('Title ')
app.mainloop()

1 个答案:

答案 0 :(得分:0)

除非你的问题有些我不理解,否则解决办法就是如果答案是肯定的话,只需调用你的函数:

def zsmessage():
    result = tkMessageBox.askquestion(...)
    if result == 'yes':
        print "yes pressed"
        controller.show_frame(PageZS)