tkinter: Switch between two grids

sms amicale.salmson at free.fr
Sat Dec 12 13:24:14 EST 2015


Hello all,

I'm sorry to ask this question, but I am a very beginer.

What I need:
1. Fullscreen application
2. On the home screen: Three row
3. When I click on the main screen, it switches to one row only.

Actually, I am not able to switch from Window1 to Window2, Window2 comes 
under Window1

Any help would be greatly appreciated.

Please, find my shameful code :

import sys
if sys.version_info[0] < 3:
     import Tkinter as Tk
else:
     import tkinter as Tk


def destroy(e): sys.exit()

class Window1():
     def __init__(self, master):
         self.frame=Tk.Frame(master, bg="Green", borderwidth=10)

         sticky=Tk.N+Tk.S+Tk.E+Tk.W
         self.frame.grid(sticky=sticky)

         self.frame.columnconfigure(0, weight=1)
         self.frame.rowconfigure(0, weight=1)
         self.frame.rowconfigure(1, weight=1)
         self.frame.rowconfigure(2, weight=1)

         self.v = Tk.StringVar()
         text = Tk.Label(self.frame, text="Text1")
         text.grid(column=0, row=0, sticky=sticky)

         self.h = Tk.StringVar()
         text = Tk.Label(self.frame, text="Text2")
         text.grid(column=0, row=1, sticky=sticky)

         self.d = Tk.StringVar()
         text = Tk.Label(self.frame, text="Text3")
         text.grid(column=0, row=2, sticky=sticky)


class Window2:
     def __init__(self, master):

         self.frame = Tk.Frame(master, bg="black", borderwidth=10)
         sticky=Tk.N+Tk.S+Tk.E+Tk.W
         self.frame.grid(sticky=sticky)

         self.v = Tk.StringVar()
         text = Tk.Label(self.frame, text="Prout")
         text.grid(column=0, row=0, sticky=sticky)

class VGui:
     def __init__(self):
         self.root = Tk.Tk()
         self.root.attributes("-fullscreen", True)
         Tk.Grid.rowconfigure(self.root, 0, weight=1)
         Tk.Grid.columnconfigure(self.root, 0, weight=1)
         self.Window1 = Window1(self.root)
         self.Window2 = Window2(self.root)

         self.root.bind("<Button-1>", self.Callback)

     def Start(self):
         Tk.mainloop()

     def Callback(self, event):
         self.Window2.frame.tkraise()

if __name__ == '__main__' :
     gui=VGui()
     gui.Start()

Thanks for reading.



More information about the Python-list mailing list