Skip to content

Instantly share code, notes, and snippets.

@vahit
Created February 9, 2015 14:46
Show Gist options
  • Save vahit/a2df818b8e371ebaf5d9 to your computer and use it in GitHub Desktop.
Save vahit/a2df818b8e371ebaf5d9 to your computer and use it in GitHub Desktop.
tkinter simple OO code II
#!/usr/sbin/env python
import tkinter as tk
class Demo1:
def __init__(self, master):
self.master = master
def create_frame(self):
self.frame = tk.Frame(self.master)
self.button = tk.Button(self.frame, text="New Window ...",
width=25, command=self.new_window)
self.button2 = tk.Button(self.frame, text='Close',
width=25, command=self.close)
self.button.pack()
self.button2.pack()
self.frame.grid()
def new_window(self):
# self.newWindow = tk.Toplevel(self.master)
self.app = Demo2(self.master)
self.close()
self.app.create_frame()
def close(self):
self.frame.grid_forget()
class Demo2:
def __init__(self, master):
self.master = master
def create_frame(self):
self.frame = tk.Frame(self.master)
self.quitButton = tk.Button(self.frame, text="Quit",
width=25, command=self.close_window)
self.quitButton.pack()
self.backButton = tk.Button(self.frame, text="Back",
width=25, command=self.back)
self.backButton.pack()
self.frame.grid()
def close_window(self):
self.master.destroy()
def back(self):
self.app = Demo1(self.master)
self.close()
self.app.create_frame()
def close(self):
self.frame.grid_forget()
def main():
root = tk.Tk()
app = Demo1(root)
app.create_frame()
root.title("Demo1")
root.mainloop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment