From fc5efd3d1e65071cd92eb7f5db3ec13223064e8c Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 11 Oct 2022 06:07:30 +0530 Subject: [PATCH 1/4] Add Tkinter folder to teachmepythonlikeiam5 --- Tkinter/tut1.py | 42 ++++++++++++++++++++++++++++++++++++++++++ Tkinter/tut2.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 Tkinter/tut1.py create mode 100644 Tkinter/tut2.py diff --git a/Tkinter/tut1.py b/Tkinter/tut1.py new file mode 100644 index 0000000..8591cf2 --- /dev/null +++ b/Tkinter/tut1.py @@ -0,0 +1,42 @@ +# ------------------------------------------------------------------------------------ +# 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 +from tkinter import * #by this you can call all functions of that particular module at single time +root=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=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 +# ------------------------------------------------------------------------------------ \ No newline at end of file diff --git a/Tkinter/tut2.py b/Tkinter/tut2.py new file mode 100644 index 0000000..c200aa7 --- /dev/null +++ b/Tkinter/tut2.py @@ -0,0 +1,39 @@ +# 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 +from tkinter import* +main=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="red",bg="yellow", 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() \ No newline at end of file From ae1f9f78c6d86b51b6aaffda530038c9c810cd60 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 13 Oct 2022 20:25:57 +0530 Subject: [PATCH 2/4] resolved all the errors for flake8 --- Tkinter/tut1.py | 26 +++++++++++++------------- Tkinter/tut2.py | 31 +++++++++++++++++-------------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/Tkinter/tut1.py b/Tkinter/tut1.py index 8591cf2..edad185 100644 --- a/Tkinter/tut1.py +++ b/Tkinter/tut1.py @@ -8,26 +8,26 @@ # Firstly, we would start with how to create a simple tkinter window - #importing modules first -from tkinter import * #by this you can call all functions of that particular module at single time -root=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 +# importing modules first +from tkinter import Tk +# from tkinter import Frame + +root = 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 +# can make it resizable upto some limit or even fix the size -main=Tk() +main = 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.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. +# 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 @@ -39,4 +39,4 @@ # ------------------------------------------------------------------------------------ # 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 -# ------------------------------------------------------------------------------------ \ No newline at end of file +# ------------------------------------------------------------------------------------ diff --git a/Tkinter/tut2.py b/Tkinter/tut2.py index c200aa7..ee85cb3 100644 --- a/Tkinter/tut2.py +++ b/Tkinter/tut2.py @@ -1,8 +1,8 @@ # 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 +# 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, +# 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 @@ -12,28 +12,31 @@ # 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 -from tkinter import* -main=Tk() +from tkinter import Tk +from tkinter import Frame +from tkinter import Button + +main = Tk() main.geometry("400x400") -#frame_widget = Frame(parent_window, attributes...) -frame_widget = Frame(main) #read about its syntax also +# 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 +# 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 +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="red",bg="yellow", 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 +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() +btn2 = Button(frame_widget_2, text="Collect", fg="blue", bg="white", height=4, width=5) +btn2.pack() -main.mainloop() \ No newline at end of file +main.mainloop() From 3c819cefd8c5c15bea784424efe484c48d25dbff Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 13 Oct 2022 20:40:58 +0530 Subject: [PATCH 3/4] _tkinter.TclError issue is solved --- Tkinter/tut1.py | 12 ++++++++++-- Tkinter/tut2.py | 8 +++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Tkinter/tut1.py b/Tkinter/tut1.py index edad185..78982b3 100644 --- a/Tkinter/tut1.py +++ b/Tkinter/tut1.py @@ -9,16 +9,24 @@ # 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 = Tk() # for versions earlier than python3 , t is in small case in Tk i.e. tk() +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 = Tk() +main = Tkinter.Tk() main.title("resizing window") # .geometry("widthxheight") main.geometry("500x400") # the window will be having this size when program starts diff --git a/Tkinter/tut2.py b/Tkinter/tut2.py index ee85cb3..cad47b6 100644 --- a/Tkinter/tut2.py +++ b/Tkinter/tut2.py @@ -12,11 +12,17 @@ # 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 = Tk() +main = Tkinter.Tk() main.geometry("400x400") # frame_widget = Frame(parent_window, attributes...) frame_widget = Frame(main) # read about its syntax also From 975976ff2635ef5bd8cda56352e042a73546ebd3 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 20 Oct 2022 05:08:12 +0530 Subject: [PATCH 4/4] removed flake8 errors --- Tkinter/tut1.py | 8 ++++---- Tkinter/tut2.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Tkinter/tut1.py b/Tkinter/tut1.py index 78982b3..ac83bcd 100644 --- a/Tkinter/tut1.py +++ b/Tkinter/tut1.py @@ -10,11 +10,11 @@ # importing modules first import tkinter -from tkinter import Tk -import sys +# from tkinter import Tk +# import sys import os -if os.environ.get('DISPLAY','') == '': +if os.environ.get('DISPLAY', '') == '': print('no display found. Using :0.0') os.environ.__setitem__('DISPLAY', ':0.0') @@ -26,7 +26,7 @@ # 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 = tkinter.Tk() main.title("resizing window") # .geometry("widthxheight") main.geometry("500x400") # the window will be having this size when program starts diff --git a/Tkinter/tut2.py b/Tkinter/tut2.py index cad47b6..20c3017 100644 --- a/Tkinter/tut2.py +++ b/Tkinter/tut2.py @@ -13,16 +13,16 @@ # 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 Tk from tkinter import Frame from tkinter import Button -import sys +# import sys import os -if os.environ.get('DISPLAY','') == '': +if os.environ.get('DISPLAY', '') == '': print('no display found. Using :0.0') os.environ.__setitem__('DISPLAY', ':0.0') -main = Tkinter.Tk() +main = tkinter.Tk() main.geometry("400x400") # frame_widget = Frame(parent_window, attributes...) frame_widget = Frame(main) # read about its syntax also