I have this code which open a frame, count 5 seconds and then open another frame. Here i have some buttons that should open different frames but they all open same second frame that is already opened by counter.

I don t get it why is this happen. Any idea or help?

import tkMessageBox
import MySQLdb
import sys
import datetime
from datetime import timedelta
import time
import calendar
import struct
import traceback
import uuid
import random
import hashlib
import Tkinter as tk
from Tkinter import *
from functools import partial
import ttk

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 (PageSTART,PageSELECT,PageZS,PageARH,PageSET,PageHLP):

            frame = F(container, self)

            self.frames[F] = frame

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

        self.show_frame(PageSTART)

    def show_frame(self, cont):

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

class PageSTART(tk.Frame):

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

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

        self.initializaresenz=Label(f,text='',font=("Arial", 18, "bold"),fg='#ff9900',width=35,height=3)
        self.initializaresenz.grid(row=4,column=0,columnspan=6)

        self.initializarestatus1=Label(f,text='Start!',font=("Arial", 18, "bold"),fg='#00cc33',width=55,height=3)
        self.initializarestatus1.grid(row=5,column=0,columnspan=6)
        self.initializarestatus2=Label(f,text='Error!',font=("Arial", 18, "bold"),fg='#ff3300',width=55,height=3)
        self.initializarestatus2.grid(row=5,column=0,columnspan=6)
        self.initializarestatus1.grid_remove()
        self.initializarestatus2.grid_remove()

        self.update_labels()

    def update_labels(self):

        now=time.time()
        diff =15 - int(now-start_app)
        txt_diff = ''

        if diff < 0:
            diff = '00'

        if diff < 10:
            txt_diff='0'+str(diff)
        else:
            txt_diff=str(diff)

        if diff < 9:
            self.initializarestatus1.grid()
            self.initializarestatus2.grid_remove()
            self.control.show_frame(PageSELECT)

        elif diff < 1:
            self.initializarestatus2.grid()
            self.initializarestatus1.grid_remove()

        self.initializaresenz.configure(text='Counting ... ' + txt_diff)

        self.after(10, self.update_labels)

class PageSELECT(tk.Frame):

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

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

        btnarh=Button(f,text='ARH',fg='blue',font=('Helvetica',18),height=1, width=10,command=lambda: controller.show_frame(PageZS))
        btnarh.grid(row=1,column=0)
        btnset=Button(f,text='SET',fg='blue',font=('Helvetica',18),height=1, width=10,command=lambda: controller.show_frame(PageSET))
        btnset.grid(row=1,column=1)
        btnhlp=Button(f,text='HLP',fg='blue',font=('Helvetica',18),height=1, width=10,command=lambda: controller.show_frame(PageHLP))
        btnhlp.grid(row=2,column=0)
        btnex=Button(f,text='EXIT',fg='blue',font=('Helvetica',18),height=1, width=10,command=self.exit)
        btnex.grid(row=2,column=1)

    def exit(self):
        mExit = tkMessageBox.askyesno(title='Exit', message='Exit ?')
        if mExit > 0:
            app.destroy()
            return

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',font=("Arial", 12, "bold"),width=35,height=0,relief='groove').grid(row=0,column=4)

class PageARH(tk.Frame):

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

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

        labelspacing=Label(f,text='Page ARH',font=("Arial", 18, "bold"),width=9,height=1).grid(row=0,column=0)

class PageSET(tk.Frame):

    def __init__(self, parent, controller):

        tk.Frame.__init__(self, parent)
        f = Frame(self)
        f.pack(side='left')

        labelspacing=Label(f,text='Page SET',font=("Arial", 18, "bold"),width=9,height=1).grid(row=0,column=0)


class PageHLP(tk.Frame):

    def __init__(self, parent, controller):

        tk.Frame.__init__(self, parent)
        f = Frame(self)
        f.pack(side='left')

        labelspacing=Label(f,text='Page HLP',font=("Arial", 18, "bold"),width=9,height=1).grid(row=0,column=0)


#Root loop
app = ChangePages()
app.geometry('600x400+0+0')
app.title('ASV Technologies ')
app.mainloop()

I wonder if there is a way in Python to simply import everything?

I wonder if there is a way in Python to simply import everything?

There is a mechanism in the py library: a mapping of the standard library. With this, you can avoid importing modules explicitely, for example

>>> import py
>>> py.std.ttk.Frame
<class ttk.Frame at 0x7f669a13a7a0>
>>> py.std.hashlib.sha256
<built-in function openssl_sha256>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.