-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathtut2.py
More file actions
48 lines (40 loc) · 2.19 KB
/
tut2.py
File metadata and controls
48 lines (40 loc) · 2.19 KB
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
# You all would be wondering what are uses of GUI and how to achieve its functionality
# now , to answer this , there is tutorial_2 where you would learn about widgets, what are they
# and we will discuss some of them
# WIDGETS: Tkinter provides various controls, such as buttons
# labels and text boxes used in a GUI application. These controls are commonly called widgets.
# There are many attributes associated with each widgets like dimensions, colors, fonts, borders, relief styles
# , text-alignment, and sometimes placeholder
# first widget to be started is with : FRAME
# frame is like a container which contains other widgets in it
# by which we can divide our window in parts and make changes to each one independently
# for simple learning first move to code, analyze how it works then you will get clear idea
import tkinter
# from tkinter import Tk
from tkinter import Frame
from tkinter import Button
# import sys
import os
if os.environ.get('DISPLAY', '') == '':
print('no display found. Using :0.0')
os.environ.__setitem__('DISPLAY', ':0.0')
main = tkinter.Tk()
main.geometry("400x400")
# frame_widget = Frame(parent_window, attributes...)
frame_widget = Frame(main) # read about its syntax also
# now you wouldn't be noticing any change as whev we do not specify dimension of frame widget
# it covers whole window now we would learn about its attriutes, like dimensions
# , border which would help you separate frame from parent window
# comment above code line
frame_widget = Frame(main)
frame_widget.pack(side='right') # this line is one of the important as many coders forget about it, thus resulting in no output
# we need to give each widget some packing status or we need to tell them their position with respect to parent window
frame_widget_2 = Frame(main)
frame_widget_2.pack(side="left")
btn1 = Button(frame_widget, text="Submit", fg="Black", bg="cyan", height=4, width=5)
btn1.pack()
# here you can see button is being located at right side of parent window, even it is not having direct connection with it
# that's possible as it is configured with frame widget which contains it
btn2 = Button(frame_widget_2, text="Collect", fg="blue", bg="white", height=4, width=5)
btn2.pack()
main.mainloop()