Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import *
- class GUI():
- def __init__(self):
- self.root = Tk()
- self.active_window = None
- self.main_Canvas = None
- def create_main_window(self): #creates the main window
- self.root.config(bg="white")
- self.root.title("pyEncryptor")
- self.root.geometry("400x400")
- self.main_Canvas = Canvas(self.root, bg="white")
- self.main_Canvas.pack(side=TOP, fill=BOTH, expand=1)
- F1 = Frame(self.main_Canvas, bg="red")
- F1.grid(row=0, column=0, sticky=NW, ipadx=100, ipady=100)
- F2 = Frame(self.main_Canvas, bg="blue")
- F2.grid(row=0, column=1, sticky=NE, ipadx=100, ipady=100)
- F3 = Frame(self.main_Canvas, bg="green")
- F3.grid(row=1, column=0, sticky=SE, ipadx=100, ipady=100)
- F4 = Frame(self. main_Canvas, bg="yellow")
- F4.grid(row=1, column=1, sticky=SW, ipadx=100, ipady=100)
- F1.bind("<Button-1>", self.options_1)
- F2.bind("<Button-1>", self.options_2)
- F3.bind("<Button-1>", self.options_3)
- F4.bind("<Button-1>", self.options_4)
- self.root.mainloop()
- def options_1(self, event):
- self.create_window(event)
- overlay = self.active_window
- L=Label(overlay, text="This is an example after clicking the red square")
- L.pack(padx=5, pady=10)
- def options_2(self, event):
- self.create_window(event)
- overlay = self.active_window
- L=Label(overlay, text="This is an example after clicking the blue square\n but this one is a little bit bigger")
- L.pack(padx=5, pady=10)
- def options_3(self, event):
- self.create_window(event)
- overlay = self.active_window
- L=Label(overlay, text="This is an example after clicking the green square")
- L.pack(padx=5, pady=10)
- def options_4(self, event):
- self.create_window(event)
- overlay = self.active_window
- 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")
- L.pack(padx=5, pady=10)
- def create_window(self, event): #create overlayed canvas
- if self.active_window != None:
- self.clear_window(Event())
- self.active_window = None
- window = Canvas(self.main_Canvas, bg="white", relief="groove", highlightbackground="black", highlightcolor="black", highlightthickness=1, borderwidth=4)
- window.place(x=self.root.winfo_pointerx() - self.root.winfo_rootx()-100, y=self.root.winfo_pointery() - self.root.winfo_rooty())
- windowFrame = Frame(window)
- windowFrame.pack(fill=BOTH, expand=1, padx= 5, pady=5)
- self.active_window = window
- return "break"
- def clear_window(self, event): #clear overlayed canvas
- if self.active_window != None:
- self.active_window.destroy()
- if __name__ == "__main__":
- app = GUI()
- app.create_main_window()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement