-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloseiconbuttondemo.py
49 lines (36 loc) · 1.49 KB
/
closeiconbuttondemo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Program to demonstrate the close and iconify methods in Python
# Import the tkinter module for GUI components
from tkinter import *
# Create CloseIconButtonDemo class based on the Frame class
class CloseIconButtonDemo(Frame):
def __init__(self, master):
super(CloseIconButtonDemo, self).__init__(master)
# Link frame to grid manager
self.grid()
# Empty row
Label(self).grid(row=2)
# Set up label for close button
Label(self, text="Click button below to close:", font="Calibri 12").grid(row=3, column=0,sticky=W)
# Create close button and call method
Button(self, text="Close", command=self.closewindow).grid(row=4, column=0, sticky=N)
# Set up label for iconify button
Label(self, text="Click button below to iconify:", font="Calibri 12").grid(row=5, column=0, sticky=W)
# Create inconify button and call method
Button(self, text="Iconify", command=self.makewindowicon).grid(row=6, column=0, sticky=N)
# method to close window
def closewindow(self):
root.destroy()
# method to make window an icon
def makewindowicon(self):
root.iconify()
# Main program below
# Create a window; create an object called "root"
root = Tk()
# title of the GUI window
root.title("Close button demonstration.")
# dimensions of the window
root.geometry("300x300")
# create ListBoxDemo object
listbox1=CloseIconButtonDemo(root)
# command that will launch the GUI application
root.mainloop()