CSC111 Programs for Week 13 2015
--D. Thiebaut (talk) 22:40, 25 April 2015 (EDT)
TKDemo0.py
# tkdemo0.py
# D. Thiebaut
# The very basic skeleton of a TKinter program
from tkinter import *
from tkinter import ttk
def main():
rootWindow = Tk()
rootWindow.mainloop()
main()
TKDemo1.py
<source lang="python">
- tkdemo0.py
- D. Thiebaut
- A Simple TKInter window with a few widgets.
from tkinter import * from tkinter import ttk
class GUI:
def __init__( self, root ): # create a button that will clear the text area button1 = ttk.Button( root, text="Clear", command = self.clear ) button1.grid( row=0, column=0 )
# create another button that will process the text inside the text area button2 = ttk.Button( root, text="Process", command = self.process ) button2.grid( row=0, column=1 )
# set a check box for selecting Smith email addresses self.showSmith = IntVar() self.showSmith.set( 1 ) # make the box checked by default check1 = ttk.Checkbutton( root, text="Show Smith", variable=self.showSmith ) check1.grid( row=0, column=2 )
# set a check box for selecting Hampshire email addresses self.showHampshire = IntVar() self.showHampshire.set( 0 ) # make the box unchecked by default check2 = ttk.Checkbutton( root, text="Show Hampshire", variable=self.showHampshire ) check2.grid( row=0, column=3 ) def clear( self ): # this will eventually clear the text area print( "clear text area" ) return
def process( self ): # this will eventually process the list of email addresses and sort it # and remove duplicates. print( "process email addresses" ) return
def main():
# create an empty window rootWindow = Tk() rootWindow.title( "CSC111 TK Demo" )
# create the GUI inside the window gui = GUI( rootWindow)
# main event loop rootWindow.mainloop()
main()