Skip to content

Commit 145f194

Browse files
committed
.
1 parent abad17e commit 145f194

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

App.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66

77
class App:
88
def __init__(self,root,title) -> None:
9+
# root is the window where all the widgits will be displayed
910
self.root = root
1011
self.root.title(title)
1112
self.root.geometry('805x440')
13+
# create a button and tell it where to display the button i.e. self.root
1214
ttk.Button(self.root,text = 'start sorting',command=self._start).grid(row=0,column=14)
15+
# now to add this created widget (button) on the screen (window (self.root))
16+
# use either grid or pack
1317
ttk.Button(self.root,text = 'shuffle',command=self._shuffle).grid(row=0,column=13)
1418
self.canvas = Canvas(self.root,width=800,height=405,highlightbackground='dodgerblue',
1519
bg = 'black',highlightthickness=2)
@@ -22,9 +26,11 @@ def __init__(self,root,title) -> None:
2226
self._shuffle()
2327

2428
def __reset_colors(self,color ='dodgerblue'):
29+
# lets create a function to reset the colors
2530
self._colors = [color for _ in range(self.N)]
2631

2732
def _shuffle(self):
33+
# define a shuffle function
2834
self.__reset_colors()
2935
random.shuffle(self.data)
3036
self._display(self._colors)
@@ -73,5 +79,33 @@ def _start(self):
7379

7480
if __name__ == '__main__':
7581
window = Style(theme = 'darkly').master
82+
# window is an instance of ttkbootstrap's Style class
7683
App(window,'Bubble sort')
77-
window.mainloop()
84+
85+
window.mainloop()
86+
# tells Python to run the Tkinter event loop.
87+
# This method listens for events, such as button clicks or keypresses,
88+
# and blocks any code that comes after it from running
89+
'''
90+
The mainloop() function in Tkinter is a method that starts an event loop,
91+
which listens for events and responds to them accordingly.
92+
It is a crucial function in GUI programming with Tkinter
93+
since it is responsible for keeping the GUI responsive
94+
and handling user input.
95+
96+
When you create a GUI application using Tkinter, you define
97+
various widgets like buttons, labels, and entry boxes, and
98+
then bind them to specific events like button clicks or key
99+
presses. Once you have set up your application, you need
100+
to start the mainloop() function to start the event loop.
101+
102+
The mainloop() function runs indefinitely until the user
103+
closes the application window or calls the quit() method.
104+
It continuously listens for events such as mouse clicks,
105+
key presses, and other user input events, and dispatches
106+
them to the appropriate widgets for processing.
107+
108+
In summary, the purpose of the mainloop() function in
109+
Tkinter is to start the event loop that listens for
110+
user input events and keeps the GUI responsive.
111+
'''

0 commit comments

Comments
 (0)