-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy path37. tkinter basics 2 - buttons.py
63 lines (37 loc) · 1.64 KB
/
37. tkinter basics 2 - buttons.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
50
51
52
53
54
55
56
57
58
59
60
61
62
'''
Hello and welcome to a basic intro to TKinter, which is the Python
binding to TK, which is a toolkit that works around the Tcl language.
The tkinter module purpose to to generate GUIs, like windows. Python is not very
popularly used for this purpose, but it is more than capable of being used
'''
# Simple enough, just import everything from tkinter.
from tkinter import *
# Here, we are creating our class, Window, and inheriting from the Frame
# class. Frame is a class from the tkinter module. (see Lib/tkinter/__init__)
class Window(Frame):
# Define settings upon initialization. Here you can specify
def __init__(self, master=None):
# parameters that you want to send through the Frame class.
Frame.__init__(self, master)
#reference to the master widget, which is the tk window
self.master = master
#with that, we want to then run init_window, which doesn't yet exist
self.init_window()
#Creation of init_window
def init_window(self):
# changing the title of our master widget
self.master.title("GUI")
# allowing the widget to take the full space of the root window
self.pack(fill=BOTH, expand=1)
# creating a button instance
quitButton = Button(self, text="Quit")#,command=self.quit)
# placing the button on my window
quitButton.place(x=0, y=0)
# root window created. Here, that would be the only window, but
# you can later have windows within windows.
root = Tk()
root.geometry("400x300")
#creation of an instance
app = Window(root)
#mainloop
root.mainloop()