-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton_in_grid.py
More file actions
35 lines (21 loc) · 870 Bytes
/
Copy pathbutton_in_grid.py
File metadata and controls
35 lines (21 loc) · 870 Bytes
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
import tkinter as tk
root = tk.Tk()
root.geometry( '200x200' )
class MyButton( ):
def __init__( self , parent ):
# Give weightings to columns and rows
self.grid_columnconfigure( 0 , weight = 1 )
self.grid_rowconfigure( 0 , weight = 1 )
self.grid_rowconfigure( 1 , weight = 1 )
# Make label
self.my_label = tk.Label( self , text = 'Hello World' )
# Place label
self.my_label.grid( column = 0 , row = 0 )
# Make button
self.my_button = tk.Button( self , text = 'Press' , command = self.do_change )
# Place button
self.my_button.grid( column = 0 , row = 1 )
def do_change( self ):
self.my_label.config( text = 'You pressed the button!' )
MyButton( root )
root.mainloop()