diff --git a/Tkinter/tut1.py b/Tkinter/tut1.py new file mode 100644 index 0000000..ac83bcd --- /dev/null +++ b/Tkinter/tut1.py @@ -0,0 +1,50 @@ +# ------------------------------------------------------------------------------------ +# Tutorial: Here, we would learn how to create simple GUIs with the help of Tkinter +# module in python, which comes pre-istalled with python, so you can directly jump on coding +# to know how to use it + +# If you are unfamiliar with what is a GUI, you can check article on realpython.com +# ------------------------------------------------------------------------------------ + +# Firstly, we would start with how to create a simple tkinter window + +# importing modules first +import tkinter +# from tkinter import Tk +# import sys +import os + +if os.environ.get('DISPLAY', '') == '': + print('no display found. Using :0.0') + os.environ.__setitem__('DISPLAY', ':0.0') + +# from tkinter import Frame + +root = tkinter.Tk() # for versions earlier than python3 , t is in small case in Tk i.e. tk() +root.mainloop() # mainloop is our ending line for any tkinter window, without it the application will not run + +# NOW Time to do some basic config with our window. Like you can give Title and, dimensions to it, +# can make it resizable upto some limit or even fix the size + +main = tkinter.Tk() +main.title("resizing window") +# .geometry("widthxheight") +main.geometry("500x400") # the window will be having this size when program starts +main.minsize(300, 200) # the lower you can resize it +main.maxsize(600, 500) # the maximum size upto which you can stretch it +main.mainloop() + +# you can even fix the position at which the window should pop at start +# for this first get some knowledge of dimensions of your desktop +# the uppermost left position acts like origin where x=y=0 +# like we move downwards , y increases and when we move towards right , x increases +# the last point or point having maximum values is at bottom right of yor desktop + +# Now for the above said property to get , copy the following line of code and replace it with main.geometry("500x400") +# ----- main.geometry("500x400+100+200") ------ 100 is value for x,200 for y + + +# ------------------------------------------------------------------------------------ +# Challenge: make some more changes with dimensions,study graph, and check whether even after giving maximum dimension +# of your screen, the tkinter window would cover all the space or not +# ------------------------------------------------------------------------------------ diff --git a/Tkinter/tut2.py b/Tkinter/tut2.py new file mode 100644 index 0000000..20c3017 --- /dev/null +++ b/Tkinter/tut2.py @@ -0,0 +1,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()