I have this code which if i press msgbox yes it opens another frame but if i do same thing from another function (counter) i get an error. Can someone help me and tell what is wrong?
import tkMessageBox
import Tkinter as tk
from Tkinter import *
from functools import partial
import time
LARGE_FONT= ("Verdana", 12)
start_app = time.time()
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()
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)
self.counter()
def counter(self):
now=time.time()
passed = 10 - int(now-start_app)
print passed
if passed < 5:
controller.show_frame(PageZS)
self.after(10, self.counter)
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()
Thanks in advance