Abstract: set a window with a label or button
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 2 12:35:28 2015
@author: yuan
"""
from Tkinter import *
class MyWindow:
def __init__(self, title='tkinter'):
self.title=title
def win_v1(self, txt):
widget=Label(None, text=txt) # make an instance of imported Label class
widget.pack() # arrange the new Label in parent widget
widget.mainloop() #calls mainloop to bring up the window and start Tkinter event loop
def win_label(self, txt):
root=Tk()
root.title(self.title)
#add a label
widget=Label(root, text=txt)
widget.config(bg='green', fg='black')
widget.config(font=('times', 20, 'normal') )
widget.config(height=5, width=25)
widget.pack(expand=YES, fill=BOTH)
root.mainloop()
def win_button(self, txt):
root=Tk()
root.title(self.title)
#add a button
widget=Button(root, text=txt, padx=5, pady=15)
widget.config(cursor='gumby')
widget.config(bg='green', fg='black')
widget.config(font=('helvetica', 20, 'bold') )
widget.pack(padx=20, pady=20)
widget.pack(expand=YES, fill=BOTH)
root.mainloop()
###main program
#the simplest label window
l=MyWindow('MyLabel')
#the window will be present on the left top corner of the screen
l.win_v1('Hello GUI world')
#some decorations of labels and titles
l.win_label('Hello world!')
#add two buttons
l.win_button('Save')
No comments:
Post a Comment