Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b3882eb

Browse files
Make root window
Add label and inactive button to window
1 parent 224cbc3 commit b3882eb

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

‎src/program1.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
'''
2+
Created on Aug 12, 2017
3+
4+
@author: Aditya
5+
'''
6+
import tkinter as tk
7+
from tkinter import ttk
8+
9+
def sayhello():
10+
root = tk.Tk() # call Tk constructor method to create new top level widget (main window)
11+
12+
# Below statement creates a label with text as a
13+
# child of root window and use pack geometry management method to put text on window
14+
tk.Label(root, text = 'Hello Python GUI').pack()
15+
16+
# ttk = themed tk widgets
17+
# create button using 'themed tk widgets' (ttk)
18+
# parent widget of button-widget is defined as 'root' variable
19+
# text displayed on button defined as text = 'Click Me'
20+
button = ttk.Button(root, text = 'Click ME')
21+
button.pack() # pack the button
22+
23+
24+
# find value of property from widget object
25+
prop_text = button['text']
26+
print('Value of \'{}\' property in button_obj is {}'.format('text', prop_text))
27+
28+
# change value on button : (Note values stored as dictionary in object)
29+
button['text'] = 'Press ME'
30+
31+
# use config command
32+
button.config(text = 'Push ME')
33+
34+
# To print the value of all propertise of widget object
35+
print(button.config())
36+
37+
# underlying TK name of the widget:
38+
# tkinter generates random number as a unique identifier (name) for each widget created
39+
print(str(button))
40+
print(str(root)) # 'rood window is identified as a '.' by tkinter (underlying name)
41+
42+
43+
root.mainloop() # run mainloop method for run window
44+
45+
def test():
46+
sayhello()
47+
if __name__ == '__main__':test()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /