Advertisement
QuantumWarpCode

Basic Python GUI

Sep 20th, 2014
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. #gui.py
  2.  
  3. import time
  4. import tkinter
  5.  
  6. class GUI(object):
  7.  
  8.     #GUI.create()
  9.     #loads interface
  10.     def create (self, parent):
  11.    
  12.         #remember the root
  13.         self.window = parent
  14.        
  15.         #simplify tkinter variables
  16.         left = tkinter.LEFT
  17.         right = tkinter.RIGHT
  18.    
  19.         self.container = tkinter.Frame(parent)
  20.         self.button1 = tkinter.Button(self.container)
  21.         #self.button2 = tkinter.Button(self.container)
  22.        
  23.         self.button1["text"]= "Hello, World!"
  24.         self.button1["background"]= "white"
  25.         self.button1.bind("<Button-1>", self.button1Click)
  26.         self.button1.bind("<ButtonRelease-1>", self.button1Release)
  27.         #self.button2["text"]= "Hello, World2!"
  28.         #self.button2["background"]= "white"
  29.        
  30.         self.container.pack()
  31.         self.button1.pack(side = left)
  32.         #self.button2.pack(side = left)
  33.        
  34.         print("Window created")
  35.        
  36.     def run (self, parent):
  37.    
  38.         #mainloop
  39.        
  40.         parent.mainloop()
  41.        
  42.         #on window close
  43.        
  44.         print("WIndows closed!")
  45.         time.sleep(1)
  46.        
  47.     def button1Click(self, event):
  48.        
  49.         self.button1["text"] = "Click!"
  50.        
  51.     def button1Release(self, event):
  52.    
  53.         self.button1["text"] = "Hello, World!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement