Advertisement
AceScottie

mvce.py

Sep 12th, 2018
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.62 KB | None | 0 0
  1. from Tkinter import *
  2.  
  3. class GUI():
  4.     def __init__(self):
  5.         self.root = Tk()
  6.         self.active_window = None
  7.         self.main_Canvas = None
  8.        
  9.     def create_main_window(self): #creates the main window
  10.         self.root.config(bg="white")
  11.         self.root.title("pyEncryptor")
  12.         self.root.geometry("400x400")
  13.         self.main_Canvas = Canvas(self.root, bg="white")
  14.         self.main_Canvas.pack(side=TOP, fill=BOTH, expand=1)
  15.         F1 = Frame(self.main_Canvas, bg="red")
  16.         F1.grid(row=0, column=0, sticky=NW, ipadx=100, ipady=100)
  17.         F2 = Frame(self.main_Canvas, bg="blue")
  18.         F2.grid(row=0, column=1, sticky=NE, ipadx=100, ipady=100)
  19.         F3 = Frame(self.main_Canvas, bg="green")
  20.         F3.grid(row=1, column=0, sticky=SE, ipadx=100, ipady=100)
  21.         F4 = Frame(self.    main_Canvas, bg="yellow")
  22.         F4.grid(row=1, column=1, sticky=SW, ipadx=100, ipady=100)
  23.         F1.bind("<Button-1>", self.options_1)
  24.         F2.bind("<Button-1>", self.options_2)
  25.         F3.bind("<Button-1>", self.options_3)
  26.         F4.bind("<Button-1>", self.options_4)
  27.         self.root.mainloop()
  28.  
  29.        
  30.     def options_1(self, event):
  31.         self.create_window(event)
  32.         overlay = self.active_window
  33.         L=Label(overlay, text="This is an example after clicking the red square")
  34.         L.pack(padx=5, pady=10)
  35.     def options_2(self, event):
  36.         self.create_window(event)
  37.         overlay = self.active_window
  38.         L=Label(overlay, text="This is an example after clicking the blue square\n but this one is a little bit bigger")
  39.         L.pack(padx=5, pady=10)
  40.     def options_3(self, event):
  41.         self.create_window(event)
  42.         overlay = self.active_window
  43.         L=Label(overlay, text="This is an example after clicking the green square")
  44.         L.pack(padx=5, pady=10)
  45.     def options_4(self, event):
  46.         self.create_window(event)
  47.         overlay = self.active_window
  48.         L=Label(overlay, text="This is an example after clicking the blue square\nbut this one is much\nmuch\nmuch\nmuch\nmuch\nmuch\nmuch\nBIGGER")
  49.         L.pack(padx=5, pady=10)
  50.        
  51.     def create_window(self, event): #create overlayed canvas
  52.         if self.active_window != None:
  53.             self.clear_window(Event())
  54.             self.active_window = None
  55.         window = Canvas(self.main_Canvas, bg="white", relief="groove", highlightbackground="black", highlightcolor="black", highlightthickness=1, borderwidth=4)
  56.         window.place(x=self.root.winfo_pointerx() - self.root.winfo_rootx()-100, y=self.root.winfo_pointery() - self.root.winfo_rooty())
  57.         windowFrame = Frame(window)
  58.         windowFrame.pack(fill=BOTH, expand=1, padx= 5, pady=5)
  59.         self.active_window = window
  60.         return "break"
  61.     def clear_window(self, event): #clear overlayed canvas
  62.         if self.active_window != None:
  63.             self.active_window.destroy()
  64.  
  65. if __name__ == "__main__":
  66.     app = GUI()
  67.     app.create_main_window()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement