WEBVTT

1
00:00:00.080 --> 00:00:04.120
<v Speaker 1>Welcome to the deep dive. Today we're diving into a

2
00:00:04.120 --> 00:00:08.359
<v Speaker 1>stack of source material all about building graphical user interfaces,

3
00:00:08.759 --> 00:00:12.240
<v Speaker 1>you know, those clickable windows with buttons and textboxes using Python.

4
00:00:12.359 --> 00:00:14.519
<v Speaker 2>And our main guide for this journey is the second

5
00:00:14.640 --> 00:00:18.399
<v Speaker 2>edition of Python gy Programming Cookbook by Burkhard A. Meyer

6
00:00:18.519 --> 00:00:19.760
<v Speaker 2>from back in twenty seventeen.

7
00:00:19.800 --> 00:00:22.359
<v Speaker 1>Okay, let's unpack this. This book sounds like it's basically

8
00:00:22.440 --> 00:00:25.440
<v Speaker 1>a collection of recipes, right, tackling everything from just like

9
00:00:25.760 --> 00:00:28.559
<v Speaker 1>getting a window to show up, yeah, to making it

10
00:00:28.600 --> 00:00:34.240
<v Speaker 1>interactive with buttons, text fields, organizing complex layouts, handling data.

11
00:00:33.679 --> 00:00:36.280
<v Speaker 2>Dealing with slow operations without freezing your app. That's a

12
00:00:36.280 --> 00:00:36.640
<v Speaker 2>big one.

13
00:00:36.719 --> 00:00:40.479
<v Speaker 1>Oh yeah, connecting to databases, even thinking about different languages

14
00:00:40.520 --> 00:00:43.320
<v Speaker 1>and testing. It seems pretty comprehensive.

15
00:00:42.799 --> 00:00:46.119
<v Speaker 2>It really is. It aims for a practical, hands on feel.

16
00:00:46.439 --> 00:00:50.119
<v Speaker 2>The author, Burkhard Meyer, has something like seventeen years in

17
00:00:50.200 --> 00:00:53.920
<v Speaker 2>the software industry, especially with Python and databases. Okay, worked

18
00:00:53.920 --> 00:00:55.880
<v Speaker 2>at various places. And there was a reviewer input too

19
00:00:55.920 --> 00:00:59.079
<v Speaker 2>from Mohit who also knows Python and security. So it

20
00:00:59.119 --> 00:01:02.119
<v Speaker 2>feels grounded in, you know, actually building stuff, right.

21
00:01:02.399 --> 00:01:04.439
<v Speaker 1>So our mission here is to sift through all these

22
00:01:04.519 --> 00:01:07.599
<v Speaker 1>recipes and concepts. We want to pull out the really

23
00:01:07.719 --> 00:01:10.719
<v Speaker 1>essential techniques, the key ideas, so you can get a

24
00:01:10.799 --> 00:01:15.519
<v Speaker 1>solid grasp of Python gui's without reading well every single line.

25
00:01:15.319 --> 00:01:17.799
<v Speaker 2>Of code, basically giving you the highlights real.

26
00:01:17.879 --> 00:01:22.000
<v Speaker 1>Exactly the informed shortcut. So where does one even begin?

27
00:01:22.799 --> 00:01:26.760
<v Speaker 1>The book starts like any good cookbook with the absolute minimum, right,

28
00:01:26.840 --> 00:01:28.439
<v Speaker 1>getting your first window on screen?

29
00:01:28.760 --> 00:01:32.040
<v Speaker 2>Yeah, using pythons built in kinter library. People usually shorten

30
00:01:32.079 --> 00:01:34.439
<v Speaker 2>it to just TK. Okay, and the starting code is

31
00:01:34.599 --> 00:01:38.239
<v Speaker 2>surprisingly simple. You import kinter you create an instance of

32
00:01:38.280 --> 00:01:42.000
<v Speaker 2>the main window class that's TK dot TK usually assign

33
00:01:42.079 --> 00:01:45.079
<v Speaker 2>it to a variable, say win, and then the absolutely

34
00:01:45.200 --> 00:01:48.319
<v Speaker 2>crucial bit win dot main loop.

35
00:01:48.239 --> 00:01:50.239
<v Speaker 1>The main lo Okay, that sounds fundamental. It's like the

36
00:01:50.280 --> 00:01:51.560
<v Speaker 1>heart of the whole thing totally.

37
00:01:51.599 --> 00:01:53.519
<v Speaker 2>It's the event loop. It just sits there, kind of

38
00:01:53.519 --> 00:01:57.719
<v Speaker 2>waiting for things to happen. Button clicks, keypresses, resizing, Oh.

39
00:01:57.599 --> 00:01:58.400
<v Speaker 1>The events.

40
00:01:58.519 --> 00:02:01.719
<v Speaker 2>Yeah, the main loop process these. Without it, your window

41
00:02:01.799 --> 00:02:04.560
<v Speaker 2>might literally just flash up and disappear because the script finishes.

42
00:02:05.079 --> 00:02:06.959
<v Speaker 2>The main loop keeps it alive and listening.

43
00:02:07.200 --> 00:02:09.240
<v Speaker 1>Got it. So it's not just displaying, it's running the

44
00:02:09.240 --> 00:02:12.159
<v Speaker 1>interactive part. And the book mentions a quick tip about

45
00:02:12.199 --> 00:02:13.319
<v Speaker 1>stopping resizing.

46
00:02:13.560 --> 00:02:16.000
<v Speaker 2>Yeah, simple one. If you want to fix size window,

47
00:02:16.879 --> 00:02:20.599
<v Speaker 2>just win dot resizable zero zero zero, easy way to

48
00:02:20.599 --> 00:02:21.080
<v Speaker 2>lock it down.

49
00:02:21.159 --> 00:02:24.639
<v Speaker 1>Okay, useful. So we have our basic window frame. But

50
00:02:24.840 --> 00:02:26.960
<v Speaker 1>an empty box isn't much of a GUI. You need

51
00:02:26.960 --> 00:02:29.960
<v Speaker 1>stuff inside it. The widgets. What are the first building

52
00:02:30.000 --> 00:02:31.439
<v Speaker 1>blocks the book introduces.

53
00:02:31.680 --> 00:02:35.360
<v Speaker 2>Well, the most basic are probably labels. Just text for

54
00:02:35.439 --> 00:02:39.080
<v Speaker 2>showing information or instructions uses TTK dot label simple text.

55
00:02:39.360 --> 00:02:42.639
<v Speaker 2>Then entry widgets. Those are your standard single line textboxes

56
00:02:42.680 --> 00:02:45.360
<v Speaker 2>for getting user input dtk dot.

57
00:02:45.280 --> 00:02:48.599
<v Speaker 1>Entry right displaying info versus getting input. And the main

58
00:02:48.639 --> 00:02:49.639
<v Speaker 1>way to trigger.

59
00:02:49.319 --> 00:02:52.080
<v Speaker 2>Actions buttons dot ttk dot button. And this is where

60
00:02:52.120 --> 00:02:55.039
<v Speaker 2>callbacks become super important. When you create a button, you

61
00:02:55.080 --> 00:02:57.240
<v Speaker 2>tell it which Python function to call when it's clicked

62
00:02:58.039 --> 00:03:00.960
<v Speaker 2>using the command argument. So you'd have my function name

63
00:03:01.400 --> 00:03:03.759
<v Speaker 2>that links the click event to your code.

64
00:03:03.840 --> 00:03:06.479
<v Speaker 1>So the click is the event command links it to

65
00:03:06.520 --> 00:03:08.159
<v Speaker 1>the callback function precisely.

66
00:03:08.879 --> 00:03:12.439
<v Speaker 2>That function just waits passively until the main loop detects

67
00:03:12.439 --> 00:03:14.879
<v Speaker 2>a click on that button, and then it gets executed.

68
00:03:15.120 --> 00:03:19.039
<v Speaker 1>Nice. The book also mentions usability things like putting the

69
00:03:19.080 --> 00:03:21.680
<v Speaker 1>cursor in the right place automatically YEP.

70
00:03:21.680 --> 00:03:24.159
<v Speaker 2>Using the focus method on a widget. So if you

71
00:03:24.199 --> 00:03:27.520
<v Speaker 2>call my entry dot focus, the cursor starts blinking in

72
00:03:27.560 --> 00:03:29.719
<v Speaker 2>that text box. Little things like that make a.

73
00:03:29.680 --> 00:03:31.199
<v Speaker 1>Difference and disabling widgets.

74
00:03:31.479 --> 00:03:33.319
<v Speaker 2>Yeah, you can set a property when you create it,

75
00:03:33.400 --> 00:03:35.960
<v Speaker 2>like a button, so it appears grayed out and doesn't

76
00:03:36.000 --> 00:03:36.879
<v Speaker 2>respond to clicks.

77
00:03:37.159 --> 00:03:41.879
<v Speaker 1>Okay, what about giving users choices not just text entry? Uh?

78
00:03:42.000 --> 00:03:44.879
<v Speaker 2>Check buttons are covered for simple on off choices like

79
00:03:44.960 --> 00:03:48.240
<v Speaker 2>a settings toggle right. They hold their state checked or unchecked,

80
00:03:48.319 --> 00:03:52.120
<v Speaker 2>usually zero or one using a special variable pickenter dot infar.

81
00:03:52.840 --> 00:03:56.159
<v Speaker 2>You can set the initial state using select an alignment.

82
00:03:56.360 --> 00:03:57.639
<v Speaker 1>You mentioned sticky before.

83
00:03:57.840 --> 00:04:01.199
<v Speaker 2>Yes, sticky tk wf and gets used with check buttons

84
00:04:01.199 --> 00:04:02.759
<v Speaker 2>to make sure they line up nicely on the left

85
00:04:02.800 --> 00:04:04.960
<v Speaker 2>side within their layout. Cell w for.

86
00:04:05.039 --> 00:04:08.039
<v Speaker 1>West got it, and radio buttons if for picking just

87
00:04:08.080 --> 00:04:09.479
<v Speaker 1>one option from a group.

88
00:04:09.560 --> 00:04:13.039
<v Speaker 2>Exactly radio buttons. The key difference is that a group

89
00:04:13.080 --> 00:04:16.560
<v Speaker 2>of radio buttons all share the same kintervariable. When you

90
00:04:16.600 --> 00:04:19.720
<v Speaker 2>click one, its value gets assigned to that variable, and

91
00:04:19.759 --> 00:04:22.279
<v Speaker 2>the others automatically de select ah.

92
00:04:22.399 --> 00:04:25.560
<v Speaker 1>So check buttons each have their own variable. Radio buttons

93
00:04:25.639 --> 00:04:26.279
<v Speaker 1>share one.

94
00:04:26.759 --> 00:04:30.639
<v Speaker 2>That's the crucial distinction for managing their state and selecting

95
00:04:30.639 --> 00:04:34.000
<v Speaker 2>A radio button can also trigger a callback immediately, maybe

96
00:04:34.040 --> 00:04:36.519
<v Speaker 2>to change something else in the GI based on the choice.

97
00:04:36.600 --> 00:04:39.680
<v Speaker 1>Okay, what about selecting numbers or from a list?

98
00:04:39.879 --> 00:04:41.839
<v Speaker 2>Spin box controls are good for that. You get a

99
00:04:41.839 --> 00:04:44.480
<v Speaker 2>little box with up down arrows. Again, cycle through numbers

100
00:04:44.600 --> 00:04:46.680
<v Speaker 2>or even a predefined list of text items.

101
00:04:46.759 --> 00:04:48.519
<v Speaker 1>Can you react when the value changes?

102
00:04:48.600 --> 00:04:50.439
<v Speaker 2>Oh yeah, just like a button, You can attach a

103
00:04:50.439 --> 00:04:53.560
<v Speaker 2>command callback that fires whenever the stin box value is changed.

104
00:04:54.120 --> 00:04:56.920
<v Speaker 2>The book shows an example of displaying the selected value

105
00:04:57.360 --> 00:04:59.600
<v Speaker 2>in say a larger text area.

106
00:05:00.120 --> 00:05:02.639
<v Speaker 1>Larger text area scroll texts exactly.

107
00:05:02.879 --> 00:05:06.680
<v Speaker 2>Scroll text really useful for multiline input or display. The

108
00:05:06.759 --> 00:05:09.920
<v Speaker 2>nice thing is features like word wrapping, wrap ek at

109
00:05:10.000 --> 00:05:13.639
<v Speaker 2>word and the scroll bars appearing automatically. They just work.

110
00:05:14.000 --> 00:05:15.959
<v Speaker 2>You mainly just defined its width and height.

111
00:05:16.160 --> 00:05:20.560
<v Speaker 1>Okay, so we can populate a window with widgets, but

112
00:05:20.600 --> 00:05:22.800
<v Speaker 1>they'll just pile up, right, How do you organize them?

113
00:05:23.120 --> 00:05:24.000
<v Speaker 1>Layout management?

114
00:05:24.120 --> 00:05:28.160
<v Speaker 2>Yeah, that's the next big step arranging things logically. The

115
00:05:28.199 --> 00:05:32.199
<v Speaker 2>core idea the book uses is nesting. You put widgets

116
00:05:32.319 --> 00:05:33.399
<v Speaker 2>inside container.

117
00:05:33.439 --> 00:05:36.879
<v Speaker 1>Fidgets like containers within container pretty much.

118
00:05:37.079 --> 00:05:39.720
<v Speaker 2>Ttk dot label frame is a key example. It's a

119
00:05:39.759 --> 00:05:42.319
<v Speaker 2>container that draws a border around its contents and has

120
00:05:42.360 --> 00:05:45.920
<v Speaker 2>a text label. You put related widgets inside a label frame.

121
00:05:46.399 --> 00:05:48.839
<v Speaker 2>Then you arrange the label frame itself within the main window,

122
00:05:49.240 --> 00:05:52.160
<v Speaker 2>maybe alongside other label frames or widgets. It helps break

123
00:05:52.199 --> 00:05:53.519
<v Speaker 2>down complexity.

124
00:05:53.040 --> 00:05:55.399
<v Speaker 1>And spacing to avoid everything being crammed together.

125
00:05:55.560 --> 00:05:59.040
<v Speaker 2>Patting pad X for horizontal space, patty for vertical space

126
00:05:59.040 --> 00:06:01.319
<v Speaker 2>around each widget. Usually set these when you place the

127
00:06:01.319 --> 00:06:02.720
<v Speaker 2>widget using the layout manager.

128
00:06:02.800 --> 00:06:05.120
<v Speaker 1>The book mentions grid mostly Yes.

129
00:06:05.240 --> 00:06:08.680
<v Speaker 2>The grid layout manager is heavily featured. It arranges widgets

130
00:06:08.720 --> 00:06:12.000
<v Speaker 2>in well a grid of rows and columns. You specify

131
00:06:12.040 --> 00:06:13.800
<v Speaker 2>the row and column for each widget.

132
00:06:13.480 --> 00:06:14.959
<v Speaker 1>And you can tweak padding later too.

133
00:06:15.319 --> 00:06:17.560
<v Speaker 2>The book points out you can use methods like grid

134
00:06:17.600 --> 00:06:20.879
<v Speaker 2>Configure after placing a widget to adjust its padding or

135
00:06:20.920 --> 00:06:22.279
<v Speaker 2>other grid options if needed.

136
00:06:22.480 --> 00:06:25.639
<v Speaker 1>What about when the user resizes the window. Do widgets

137
00:06:25.680 --> 00:06:27.920
<v Speaker 1>just stay fixed or can they stretch.

138
00:06:27.680 --> 00:06:30.920
<v Speaker 2>Ah dynamic expansion. That's where Sticky really comes into play again.

139
00:06:31.000 --> 00:06:34.040
<v Speaker 2>We saw sticky tk dot W for left alignment, but

140
00:06:34.120 --> 00:06:37.160
<v Speaker 2>you can use tk E eastwright, TK in north top,

141
00:06:37.319 --> 00:06:41.480
<v Speaker 2>tks self bottom or combinations like TK dot n SEW

142
00:06:41.839 --> 00:06:44.680
<v Speaker 2>to make a widget stretch and fill the entire grid cell.

143
00:06:44.720 --> 00:06:47.360
<v Speaker 2>It's in horizontally and vertically as the window.

144
00:06:47.079 --> 00:06:48.839
<v Speaker 1>Resizes and spanning multiple cells.

145
00:06:48.920 --> 00:06:51.759
<v Speaker 2>Also crucial, column span two makes a widget take up

146
00:06:51.759 --> 00:06:55.560
<v Speaker 2>two columns. Rospan three takes three rows, combining sicki and columns.

147
00:06:55.600 --> 00:06:58.399
<v Speaker 2>Thin row span gives you really fine grain control over

148
00:06:58.439 --> 00:06:59.600
<v Speaker 2>how your layout adapts.

149
00:07:00.040 --> 00:07:02.560
<v Speaker 1>Grid is the main tool here. What if the GUI

150
00:07:02.759 --> 00:07:05.720
<v Speaker 1>has like tons of options, does it just become one

151
00:07:05.759 --> 00:07:06.480
<v Speaker 1>giant window.

152
00:07:06.680 --> 00:07:09.920
<v Speaker 2>That's where TTK dot notebook comes in. It creates tabbed interfaces.

153
00:07:09.920 --> 00:07:12.480
<v Speaker 2>You put different sets of controls on different tabs, keeps

154
00:07:12.480 --> 00:07:14.160
<v Speaker 2>the main window much cleaner tabs.

155
00:07:14.199 --> 00:07:18.160
<v Speaker 1>Okay, that makes sense for complexity. Moving beyond structure, what

156
00:07:18.240 --> 00:07:21.399
<v Speaker 1>about the look and feel, making it polished? Giving feedback?

157
00:07:21.839 --> 00:07:25.480
<v Speaker 2>Right? Standard pop up messages are a basic need. Kinder

158
00:07:25.480 --> 00:07:29.120
<v Speaker 2>has built in message box functions show info for infos,

159
00:07:29.160 --> 00:07:31.000
<v Speaker 2>show warning for warnings, shower for.

160
00:07:31.079 --> 00:07:33.839
<v Speaker 1>Errors, and they pause the main GUI.

161
00:07:34.120 --> 00:07:37.040
<v Speaker 2>Yes, they're modal. The user has to dismiss the message

162
00:07:37.040 --> 00:07:39.519
<v Speaker 2>box before they can interact with the main window. Again

163
00:07:40.120 --> 00:07:41.040
<v Speaker 2>important behavior.

164
00:07:41.240 --> 00:07:44.800
<v Speaker 1>The book mentions independent message boxes. What's that about.

165
00:07:44.920 --> 00:07:47.680
<v Speaker 2>It's more about maybe structuring your code so the call

166
00:07:47.839 --> 00:07:50.079
<v Speaker 2>to show a message box is in its own function,

167
00:07:50.480 --> 00:07:53.519
<v Speaker 2>perhaps for reuse. There's a small code trick mention to

168
00:07:53.560 --> 00:07:55.720
<v Speaker 2>get the text into the body, not the title. And

169
00:07:55.759 --> 00:07:58.639
<v Speaker 2>also a reminder if you create a tk instance just

170
00:07:58.680 --> 00:08:01.519
<v Speaker 2>to use a message box, might need wind dot withdraw

171
00:08:01.800 --> 00:08:04.160
<v Speaker 2>to hide the blank extra window that kinder.

172
00:08:03.959 --> 00:08:07.240
<v Speaker 1>Creates little details. What about customizing the main window itself

173
00:08:07.360 --> 00:08:09.000
<v Speaker 1>title icon pzps.

174
00:08:09.360 --> 00:08:11.319
<v Speaker 2>Setting the title is just a method call wind dot

175
00:08:11.360 --> 00:08:14.399
<v Speaker 2>title my app. The icon usually needs a specific file

176
00:08:14.439 --> 00:08:17.240
<v Speaker 2>format dot ico on Windows, and you might need the

177
00:08:17.279 --> 00:08:18.319
<v Speaker 2>full paths to the file.

178
00:08:18.439 --> 00:08:22.279
<v Speaker 1>Any other visual tweaks mentioned like three D effects, Yeah.

179
00:08:22.120 --> 00:08:25.399
<v Speaker 2>The relief property comes up again. Setting relief sunken or

180
00:08:25.439 --> 00:08:28.600
<v Speaker 2>relief raised on widgets like frames or labels can give

181
00:08:28.639 --> 00:08:31.959
<v Speaker 2>them that classic embossed or debossed look adds a bit

182
00:08:32.000 --> 00:08:32.639
<v Speaker 2>of depth.

183
00:08:32.480 --> 00:08:35.039
<v Speaker 1>And those little helper texts when you hover over something.

184
00:08:35.279 --> 00:08:38.519
<v Speaker 2>Tooltips, Yeah, the book shows how to implement them. It

185
00:08:38.559 --> 00:08:42.240
<v Speaker 2>actually suggests using an object oriented approach creating a tooltip

186
00:08:42.279 --> 00:08:46.360
<v Speaker 2>class ahop again Yeah, it makes the tooltip logic reusable

187
00:08:46.399 --> 00:08:48.320
<v Speaker 2>and cleaner to attach to different widgets.

188
00:08:48.440 --> 00:08:52.399
<v Speaker 1>Okay, And for tasks that take a while showing progress.

189
00:08:52.080 --> 00:08:54.960
<v Speaker 2>The standard TTK dot progress bar you add it to

190
00:08:55.000 --> 00:08:57.320
<v Speaker 2>your layout and the book shows how to start its

191
00:08:57.360 --> 00:09:00.600
<v Speaker 2>animation when a task begins and stop it when done,

192
00:09:01.159 --> 00:09:03.200
<v Speaker 2>basic visual feedback that something's happening.

193
00:09:03.240 --> 00:09:06.279
<v Speaker 1>This feels like a natural lead into handling data within

194
00:09:06.320 --> 00:09:10.240
<v Speaker 1>the dui and maybe where OP really starts to shine definitely.

195
00:09:10.559 --> 00:09:14.200
<v Speaker 2>First, the book introduces special tinter variable types like stringvar.

196
00:09:14.480 --> 00:09:16.519
<v Speaker 2>These aren't just normal Python strings.

197
00:09:16.120 --> 00:09:16.919
<v Speaker 1>How are they different?

198
00:09:17.000 --> 00:09:19.960
<v Speaker 2>They're designed to be linked directly to widgets. If you

199
00:09:20.039 --> 00:09:23.000
<v Speaker 2>link a stringvar to an entry widget, changing the string

200
00:09:23.120 --> 00:09:25.720
<v Speaker 2>bar in your code automatically updates the text in the

201
00:09:25.840 --> 00:09:29.240
<v Speaker 2>entry box, and typing in the entry box updates the stringvar.

202
00:09:29.440 --> 00:09:31.639
<v Speaker 1>Oh two way binding kind of yeah.

203
00:09:31.879 --> 00:09:34.080
<v Speaker 2>Use methods like dot set to put a value into

204
00:09:34.120 --> 00:09:36.919
<v Speaker 2>the string bar and dot get to recrieve the current

205
00:09:37.039 --> 00:09:37.679
<v Speaker 2>value from it.

206
00:09:37.879 --> 00:09:39.879
<v Speaker 1>And the book notes a quirk about needing a TK

207
00:09:39.960 --> 00:09:42.639
<v Speaker 1>instance even just to create a string bar, even if

208
00:09:42.639 --> 00:09:43.440
<v Speaker 1>you hide the window.

209
00:09:43.960 --> 00:09:46.679
<v Speaker 2>Yeah, it's a bit weird. These ticket tenor variables rely

210
00:09:46.799 --> 00:09:50.480
<v Speaker 2>on the underlying TK machinery being initialized, which happens when

211
00:09:50.519 --> 00:09:53.480
<v Speaker 2>you create TK. So even for non visual use, you

212
00:09:53.519 --> 00:09:57.240
<v Speaker 2>might need root ektktk root dot withdrawal.

213
00:09:57.600 --> 00:10:00.399
<v Speaker 1>So calling dot get on these variables or directly on

214
00:10:00.399 --> 00:10:02.960
<v Speaker 1>a widgets like entry is how you pull the user's

215
00:10:03.039 --> 00:10:05.360
<v Speaker 1>input back into your Python logic.

216
00:10:05.559 --> 00:10:07.879
<v Speaker 2>That's the main way. Once you get the value, it's

217
00:10:07.919 --> 00:10:11.399
<v Speaker 2>just a standard Python string or number or whatever, and

218
00:10:11.440 --> 00:10:12.960
<v Speaker 2>you can work with it. The trick is when to

219
00:10:13.000 --> 00:10:15.279
<v Speaker 2>call dot get, usually inside a callbad function.

220
00:10:15.600 --> 00:10:19.120
<v Speaker 1>The book mentions using module level global variables for simple

221
00:10:19.200 --> 00:10:22.519
<v Speaker 1>data sharing, but then pushes towards op pretty strongly.

222
00:10:22.879 --> 00:10:26.559
<v Speaker 2>Why well, globals are tempting for super simple scripts, quick

223
00:10:26.600 --> 00:10:29.279
<v Speaker 2>and easy, but as soon as your GUI gets even

224
00:10:29.440 --> 00:10:33.240
<v Speaker 2>a little bit complex, tracking which function modified which global

225
00:10:33.320 --> 00:10:37.120
<v Speaker 2>variable becomes a nightmare, really hard to debug OPI. Using

226
00:10:37.120 --> 00:10:41.440
<v Speaker 2>classes provides encapsulation. You bundle the data as attributes of

227
00:10:41.480 --> 00:10:44.840
<v Speaker 2>an object, together with the methods functions belonging to the

228
00:10:44.840 --> 00:10:48.159
<v Speaker 2>object that operate on that data. It keeps things organized,

229
00:10:48.240 --> 00:10:51.960
<v Speaker 2>prevents accidental modification from unrelated code, and makes the whole

230
00:10:51.960 --> 00:10:54.039
<v Speaker 2>thing much easier to maintain and extend later.

231
00:10:54.159 --> 00:10:56.360
<v Speaker 1>So a method is just a function inside a class

232
00:10:56.360 --> 00:10:57.879
<v Speaker 1>that acts on the classes data.

233
00:10:57.679 --> 00:11:00.919
<v Speaker 2>Pretty much, and it usually takes self as it's first argument,

234
00:11:01.120 --> 00:11:03.960
<v Speaker 2>which refers to the specific object instance it's working with.

235
00:11:04.360 --> 00:11:08.480
<v Speaker 2>The book really emphasizes trying to refactor a messy NONOOPI

236
00:11:08.600 --> 00:11:12.919
<v Speaker 2>procedural GUI into oop later is painful. It's much better

237
00:11:12.960 --> 00:11:14.919
<v Speaker 2>to start with an OP structure if your project is

238
00:11:14.960 --> 00:11:16.559
<v Speaker 2>going to be anything beyond trivial.

239
00:11:16.240 --> 00:11:18.279
<v Speaker 1>And this connects back to the event driven nature.

240
00:11:18.600 --> 00:11:22.440
<v Speaker 2>Absolutely, the GUI sits there, an event happens button click,

241
00:11:23.039 --> 00:11:26.000
<v Speaker 2>the main loop directs it to the callback. That callback

242
00:11:26.039 --> 00:11:28.720
<v Speaker 2>is often an OP method self dot on button click,

243
00:11:29.080 --> 00:11:31.919
<v Speaker 2>which then uses self to access the object's data, maybe

244
00:11:31.960 --> 00:11:35.279
<v Speaker 2>calls dot get on some widgets, does calculations, and maybe

245
00:11:35.279 --> 00:11:38.000
<v Speaker 2>calls dot set on other widgets to update the display.

246
00:11:38.120 --> 00:11:40.159
<v Speaker 1>Okay, this next one is where I think a lot

247
00:11:40.200 --> 00:11:43.720
<v Speaker 1>of people, including me, have hit a wall. Initially, you

248
00:11:43.759 --> 00:11:46.159
<v Speaker 1>click a button that app needs to do something slow,

249
00:11:46.200 --> 00:11:48.759
<v Speaker 1>and the whole GUI just freezes.

250
00:11:48.919 --> 00:11:53.440
<v Speaker 2>Ah. Yes, the dreaded unresponsive GUI. It's a classic symptom

251
00:11:53.480 --> 00:11:56.320
<v Speaker 2>of doing long running tasks directly in the main GUI thread.

252
00:11:56.360 --> 00:11:59.519
<v Speaker 2>Why does it happen because basic kinter and many GI

253
00:11:59.559 --> 00:12:02.519
<v Speaker 2>toolkits runs its event loop main loop in a single thread.

254
00:12:02.919 --> 00:12:05.279
<v Speaker 2>If that thread gets busy doing something else like downloading

255
00:12:05.279 --> 00:12:08.960
<v Speaker 2>a big file, running a complex calculation, querying a slow database,

256
00:12:09.200 --> 00:12:11.840
<v Speaker 2>it can't process other events. It can't redraw the window,

257
00:12:12.000 --> 00:12:14.000
<v Speaker 2>respond to clicks anything. It's blocked.

258
00:12:14.639 --> 00:12:15.480
<v Speaker 1>So what's the fix?

259
00:12:15.919 --> 00:12:19.240
<v Speaker 2>Multi threading? You need to run that long running task

260
00:12:19.399 --> 00:12:22.480
<v Speaker 2>in a separate thread. The main thread stays free to

261
00:12:22.559 --> 00:12:25.639
<v Speaker 2>run the main loop and keep the GI responsive while

262
00:12:25.639 --> 00:12:28.039
<v Speaker 2>the worker thread chugs away in the background.

263
00:12:28.240 --> 00:12:31.759
<v Speaker 1>Okay, threads. The book distinguishes between threads and processes.

264
00:12:31.840 --> 00:12:36.000
<v Speaker 2>Briefly, Yes, Processes are more isolated, each with its own memory.

265
00:12:36.399 --> 00:12:39.559
<v Speaker 2>Threads run within the same process and share memory. For

266
00:12:39.679 --> 00:12:43.159
<v Speaker 2>tasks within a single GUI application that need to communicate

267
00:12:43.200 --> 00:12:46.320
<v Speaker 2>back to the GUI, threads are often simpler because sharing

268
00:12:46.399 --> 00:12:47.320
<v Speaker 2>data is easier.

269
00:12:47.679 --> 00:12:51.039
<v Speaker 1>Can that worker thread directly update a techer and widget

270
00:12:51.120 --> 00:12:52.960
<v Speaker 1>like change a labels text when it's done?

271
00:12:53.480 --> 00:12:57.240
<v Speaker 2>Generally No, that's not thread safe. Directly manipulating taker widgets

272
00:12:57.240 --> 00:13:00.399
<v Speaker 2>from a background thread can cause crashes or weird behavior.

273
00:13:00.559 --> 00:13:03.200
<v Speaker 1>So how does the worker thread tell the main GUI thread, Hey,

274
00:13:03.360 --> 00:13:04.720
<v Speaker 1>I'm done, here's the result.

275
00:13:04.840 --> 00:13:08.879
<v Speaker 2>The standard safeway is using Python's q Q. It's a

276
00:13:08.960 --> 00:13:12.159
<v Speaker 2>data structure specifically designed for thread safe communication.

277
00:13:12.320 --> 00:13:14.759
<v Speaker 1>A que like a waiting line exactly.

278
00:13:15.000 --> 00:13:18.600
<v Speaker 2>The worker thread puts its result onto the que mi

279
00:13:18.799 --> 00:13:23.360
<v Speaker 2>que dot dwizzled. The main GUI thread meanwhile periodically checks

280
00:13:23.399 --> 00:13:26.440
<v Speaker 2>the queue mi qu dot get no weight. If there's

281
00:13:26.440 --> 00:13:29.279
<v Speaker 2>something there, it safely pulls the result off and updates

282
00:13:29.320 --> 00:13:30.799
<v Speaker 2>the GUI widgets from within the.

283
00:13:30.720 --> 00:13:33.279
<v Speaker 1>Main thread, so the Q acts as a safe ordered

284
00:13:33.279 --> 00:13:34.600
<v Speaker 1>mailbox between threads.

285
00:13:34.799 --> 00:13:39.320
<v Speaker 2>Perfect analogy. It decouples the threads FIFO first in, first

286
00:13:39.320 --> 00:13:42.519
<v Speaker 2>out means results are typically processed in the order they finish.

287
00:13:42.919 --> 00:13:45.159
<v Speaker 2>The book shows how you can pass a Q object around,

288
00:13:45.399 --> 00:13:47.799
<v Speaker 2>letting different parts of your code, even in separate modules,

289
00:13:48.000 --> 00:13:50.440
<v Speaker 2>feed results back to the GUI thread without freezing it.

290
00:13:50.559 --> 00:13:53.519
<v Speaker 1>And common examples of slow tasks shown are things like

291
00:13:53.559 --> 00:13:55.360
<v Speaker 1>file operations or network calls.

292
00:13:55.639 --> 00:13:58.679
<v Speaker 2>Yes, using kinter dot request dot a filename is quick,

293
00:13:58.960 --> 00:14:02.519
<v Speaker 2>but actually reading or writing a large file could block. Similarly,

294
00:14:02.600 --> 00:14:05.639
<v Speaker 2>using erallib dot request dot eurolopin to fetch web data

295
00:14:05.879 --> 00:14:08.120
<v Speaker 2>definitely needs a thread if the network is slow where

296
00:14:08.159 --> 00:14:11.080
<v Speaker 2>the download is large. The book also stresses using try

297
00:14:11.159 --> 00:14:14.200
<v Speaker 2>except blocks around network code to handle potential errors.

298
00:14:14.000 --> 00:14:17.720
<v Speaker 1>Gracefully makes sense okay, shifting gears to data persistence. The

299
00:14:17.720 --> 00:14:21.519
<v Speaker 1>book dives into connecting to my SQL databases, specifically.

300
00:14:21.159 --> 00:14:24.440
<v Speaker 2>Right, a very common requirement. It uses the miceql dot

301
00:14:24.519 --> 00:14:27.840
<v Speaker 2>connector library, which is the official driver from Oracle.

302
00:14:27.480 --> 00:14:31.080
<v Speaker 1>My school, and the first warning is about security absolutely critical.

303
00:14:31.159 --> 00:14:35.519
<v Speaker 2>The book hammers this home do not put your database

304
00:14:35.879 --> 00:14:39.320
<v Speaker 2>username and password directly in your Python source code. It's

305
00:14:39.360 --> 00:14:42.279
<v Speaker 2>a huge security risk if that code ever gets shared

306
00:14:42.360 --> 00:14:42.919
<v Speaker 2>or exposed.

307
00:14:43.000 --> 00:14:43.720
<v Speaker 1>So what should you do?

308
00:14:44.279 --> 00:14:47.600
<v Speaker 2>Store credential separately? Maybe in a configuration file that's kept

309
00:14:47.639 --> 00:14:50.720
<v Speaker 2>in a secure location, has restricted permissions and is read

310
00:14:50.720 --> 00:14:54.159
<v Speaker 2>by your application at runtime, or use environment variables or

311
00:14:54.200 --> 00:14:57.240
<v Speaker 2>a secrets management system, just not hard coded.

312
00:14:57.360 --> 00:14:59.960
<v Speaker 1>Okay, what basic database operations does it cover?

313
00:15:00.320 --> 00:15:04.360
<v Speaker 2>The core crwould operations select to fetch data, insert to

314
00:15:04.399 --> 00:15:08.320
<v Speaker 2>add rows, update to change existing rows, delete to remove rows.

315
00:15:08.559 --> 00:15:12.080
<v Speaker 2>It also briefly introduces essential database concepts like primary keys,

316
00:15:12.200 --> 00:15:16.080
<v Speaker 2>unique IDs for rows and foreign keys, linking related tables.

317
00:15:16.320 --> 00:15:18.600
<v Speaker 1>And is there a tool mentioned for working with the

318
00:15:18.679 --> 00:15:20.080
<v Speaker 1>database outside of Python.

319
00:15:20.440 --> 00:15:23.879
<v Speaker 2>Yeah, myseql workbench. It's a free GI tool provided by

320
00:15:23.879 --> 00:15:28.440
<v Speaker 2>myseql itself, really helpful during development for designing your database schema,

321
00:15:28.759 --> 00:15:32.200
<v Speaker 2>running test SQL queries, checking data without needing to build

322
00:15:32.240 --> 00:15:33.399
<v Speaker 2>all that into your Python app.

323
00:15:33.440 --> 00:15:36.559
<v Speaker 1>First, Okay, let's talk about making apps for a global audience.

324
00:15:36.799 --> 00:15:40.879
<v Speaker 1>Internationalization and localization I eighteen N and L ten N right.

325
00:15:41.000 --> 00:15:44.679
<v Speaker 2>Internationalization I eighteen N I plus eighteen letters plus N

326
00:15:45.159 --> 00:15:47.440
<v Speaker 2>is about designing your app so it can be adapted.

327
00:15:47.840 --> 00:15:51.200
<v Speaker 2>The main part is separating all user visible text labels,

328
00:15:51.240 --> 00:15:53.759
<v Speaker 2>button text messages from your code logic. How do you

329
00:15:53.840 --> 00:15:56.240
<v Speaker 2>do that? The book shows using a simple Python class

330
00:15:56.320 --> 00:15:59.320
<v Speaker 2>is a I eighteen n that holds dictionaries of strings

331
00:15:59.320 --> 00:16:02.159
<v Speaker 2>for different language maybe self dot strings and like you

332
00:16:02.200 --> 00:16:05.039
<v Speaker 2>think kell okay, then in your guy code instead of

333
00:16:05.080 --> 00:16:07.879
<v Speaker 2>tdk dot label to ttk dot label ticks self dot

334
00:16:07.919 --> 00:16:09.960
<v Speaker 2>I t and n dot gets string, gets string greeting

335
00:16:10.240 --> 00:16:12.919
<v Speaker 2>by changing which language dictionary the I eighten n object

336
00:16:13.000 --> 00:16:15.360
<v Speaker 2>uses eg self dot I ten n dot I ten

337
00:16:15.480 --> 00:16:18.279
<v Speaker 2>nd low the whole GUI can switch language.

338
00:16:18.320 --> 00:16:21.279
<v Speaker 1>That's clever and localization L ten N. That's more than

339
00:16:21.320 --> 00:16:22.000
<v Speaker 1>just language.

340
00:16:22.159 --> 00:16:25.000
<v Speaker 2>Yeah, L ten N L plus ten letters plus n

341
00:16:25.360 --> 00:16:28.799
<v Speaker 2>is the actual adaptation to a specific locale. It includes

342
00:16:28.840 --> 00:16:31.240
<v Speaker 2>things like date time formats M and D d y

343
00:16:31.399 --> 00:16:34.919
<v Speaker 2>y versus D M M y y, currency symbols, number

344
00:16:34.960 --> 00:16:38.799
<v Speaker 2>formatting using commas or periods as decimal separators, and crucially,

345
00:16:39.200 --> 00:16:39.960
<v Speaker 2>time zones.

346
00:16:40.440 --> 00:16:42.000
<v Speaker 1>Time zones sound tricky.

347
00:16:41.759 --> 00:16:44.399
<v Speaker 2>They can be. The book shows using pythons built in

348
00:16:44.519 --> 00:16:47.720
<v Speaker 2>DateTime module along with the third party pits library to

349
00:16:47.799 --> 00:16:51.960
<v Speaker 2>handle time zone conversions correctly, like displaying a time recorded

350
00:16:52.000 --> 00:16:54.679
<v Speaker 2>in UTC for someone in say Pacific time.

351
00:16:54.919 --> 00:16:58.960
<v Speaker 1>What about displaying characters from other languages like German, Lauts

352
00:16:59.080 --> 00:17:00.519
<v Speaker 1>or maybe Asians.

353
00:17:00.720 --> 00:17:03.799
<v Speaker 2>Unicode handling Python three is generally pretty good with Unicode strings,

354
00:17:03.960 --> 00:17:07.480
<v Speaker 2>but sometimes, depending on your operating system, terminal or IDE settings,

355
00:17:07.759 --> 00:17:11.079
<v Speaker 2>you might run into encoding issues where characters display incorrectly.

356
00:17:11.160 --> 00:17:12.839
<v Speaker 1>Any solutions mentioned using.

357
00:17:12.599 --> 00:17:15.359
<v Speaker 2>Python's direct Unicode escapes like U TOFC for you can

358
00:17:15.400 --> 00:17:18.680
<v Speaker 2>be a robust way, or more commonly, ensuring your source

359
00:17:18.680 --> 00:17:21.440
<v Speaker 2>code files are saved with UTF eight encoding and that

360
00:17:21.480 --> 00:17:24.359
<v Speaker 2>your development environment like pit of eclip settings mentioned in

361
00:17:24.400 --> 00:17:27.079
<v Speaker 2>the book is configured to handle UTFA correctly.

362
00:17:27.279 --> 00:17:29.599
<v Speaker 1>Okay, building all this is great, but it needs to

363
00:17:29.599 --> 00:17:34.960
<v Speaker 1>work reliably. Testing. How does the book approach ensuring quality?

364
00:17:35.599 --> 00:17:38.680
<v Speaker 2>It emphasizes that testing isn't just one thing. It happens

365
00:17:38.680 --> 00:17:41.960
<v Speaker 2>at multiple levels. There's developer testing just running the code.

366
00:17:41.960 --> 00:17:46.440
<v Speaker 2>Maybe the IDE catches syntax errors using source control like GIT,

367
00:17:46.599 --> 00:17:50.640
<v Speaker 2>which helps catch integration conflicts, API testing testing the non

368
00:17:50.680 --> 00:17:54.480
<v Speaker 2>GUI logic, integration testing, making sure different parts work together,

369
00:17:54.759 --> 00:17:56.440
<v Speaker 2>and finally end user testing.

370
00:17:56.640 --> 00:17:58.200
<v Speaker 1>All catch in different kinds of bugs.

371
00:17:58.279 --> 00:18:01.880
<v Speaker 2>Exactly, you need a mix for debugging when things go

372
00:18:01.960 --> 00:18:05.200
<v Speaker 2>wrong during development. Buggers, Yeah, using your IDEs debugger is

373
00:18:05.279 --> 00:18:08.640
<v Speaker 2>key setting break points to pause the code, inspecting the

374
00:18:08.680 --> 00:18:11.640
<v Speaker 2>values of variables at that point using watches stepping through

375
00:18:11.640 --> 00:18:14.400
<v Speaker 2>code line by line. The book notes that in GUIs

376
00:18:14.440 --> 00:18:17.279
<v Speaker 2>you often want to put break points inside your event

377
00:18:17.319 --> 00:18:20.720
<v Speaker 2>handler functions like button callbacks, because that's where the action

378
00:18:20.799 --> 00:18:24.519
<v Speaker 2>happens after the mainloop dispatches an event. It also suggests

379
00:18:24.559 --> 00:18:28.079
<v Speaker 2>setting up your own simple logging using Python's logging module.

380
00:18:28.279 --> 00:18:30.480
<v Speaker 2>May be configured in the if name equals main part

381
00:18:30.519 --> 00:18:31.119
<v Speaker 2>of your script.

382
00:18:31.240 --> 00:18:32.279
<v Speaker 1>Why custom logging.

383
00:18:32.400 --> 00:18:35.000
<v Speaker 2>It gives you more control than just print statements. You

384
00:18:35.039 --> 00:18:39.480
<v Speaker 2>can set different logging levels, debug info, warning, error, easily

385
00:18:39.480 --> 00:18:42.319
<v Speaker 2>switch between logging to the console or a file, and

386
00:18:42.400 --> 00:18:45.880
<v Speaker 2>filter messages. It's great for tracing what your application is doing,

387
00:18:46.200 --> 00:18:48.079
<v Speaker 2>especially in response to events.

388
00:18:47.759 --> 00:18:49.880
<v Speaker 1>And for more formal automated tests.

389
00:18:50.319 --> 00:18:54.079
<v Speaker 2>Python's built in unitist framework is the standard shown. The

390
00:18:54.160 --> 00:18:57.039
<v Speaker 2>idea is to write separate test code that imports your

391
00:18:57.039 --> 00:18:59.640
<v Speaker 2>application code and verifies its behavior.

392
00:19:00.039 --> 00:19:00.599
<v Speaker 1>Does that work?

393
00:19:00.799 --> 00:19:03.880
<v Speaker 2>You create test classes inheriting from unitist dot test case.

394
00:19:04.559 --> 00:19:07.839
<v Speaker 2>Inside you write methods whose names start with test. Within

395
00:19:07.880 --> 00:19:10.440
<v Speaker 2>these methods, you call parts of your application code and

396
00:19:10.599 --> 00:19:14.519
<v Speaker 2>use assertion methods like self dot assert equal actual expected

397
00:19:14.880 --> 00:19:16.240
<v Speaker 2>to check if the results are correct.

398
00:19:16.319 --> 00:19:19.200
<v Speaker 1>But how do you test gy interactions with unitist. You

399
00:19:19.240 --> 00:19:21.720
<v Speaker 1>can't easily click a button in a test script.

400
00:19:21.680 --> 00:19:24.960
<v Speaker 2>Right, You usually don't simulate the physical click. Instead, you

401
00:19:25.039 --> 00:19:28.440
<v Speaker 2>test the consequences of the click. The book gives an example.

402
00:19:28.960 --> 00:19:32.519
<v Speaker 2>You directly call the callback function associated with a radio

403
00:19:32.559 --> 00:19:36.599
<v Speaker 2>button in your test code. Then you check if, say

404
00:19:36.960 --> 00:19:39.960
<v Speaker 2>a label widget that should have been updated by that callback,

405
00:19:40.319 --> 00:19:44.079
<v Speaker 2>now contains the expected text. You're testing the logic triggered

406
00:19:44.079 --> 00:19:44.960
<v Speaker 2>by the event.

407
00:19:44.720 --> 00:19:47.200
<v Speaker 1>Ah testing the callbacks effect exactly.

408
00:19:47.640 --> 00:19:50.680
<v Speaker 2>The book also mentions test fixtures set up in tear

409
00:19:50.720 --> 00:19:53.279
<v Speaker 2>down methods, which let you run code to prepare the

410
00:19:53.400 --> 00:19:56.839
<v Speaker 2>environment before each test, like creating objects and clean up afterwards.

411
00:19:56.920 --> 00:20:00.640
<v Speaker 1>Okay, Ticker is built in and clearly powerful, but Python's

412
00:20:00.680 --> 00:20:03.599
<v Speaker 1>ecosystem is huge. Does the book look at any alternative

413
00:20:03.640 --> 00:20:04.720
<v Speaker 1>GUI libraries?

414
00:20:04.839 --> 00:20:07.160
<v Speaker 2>It does. It takes a look at wx Python, specifically

415
00:20:07.200 --> 00:20:09.880
<v Speaker 2>the Phoenix version, which works with modern Python. It's another

416
00:20:10.000 --> 00:20:11.319
<v Speaker 2>very popular mature library.

417
00:20:11.359 --> 00:20:13.079
<v Speaker 1>How's it different from Ticker, Well.

418
00:20:12.880 --> 00:20:15.400
<v Speaker 2>First, you have to install it separately. It's not built in,

419
00:20:15.880 --> 00:20:19.960
<v Speaker 2>often done using pipt af files. The basic structure feels

420
00:20:19.960 --> 00:20:24.359
<v Speaker 2>conceptually similar, though you initialize in wx dot app create

421
00:20:24.400 --> 00:20:28.400
<v Speaker 2>a main window, wx dot frame, add widgets, and start

422
00:20:28.400 --> 00:20:31.720
<v Speaker 2>a mainloof the book notes it has good documentation and

423
00:20:31.799 --> 00:20:35.599
<v Speaker 2>often provides widgets that look more native on different operating systems. Plus,

424
00:20:35.599 --> 00:20:38.160
<v Speaker 2>things like standard menu mars are easy to set up.

425
00:20:38.200 --> 00:20:41.519
<v Speaker 1>Can you mix them? Put a wx Python widget inside

426
00:20:41.559 --> 00:20:43.799
<v Speaker 1>a kinter window or vice versa.

427
00:20:43.960 --> 00:20:47.240
<v Speaker 2>The book explores this idea, but the conclusion seems to

428
00:20:47.279 --> 00:20:50.559
<v Speaker 2>be it's usually not a good idea. Trying to embed

429
00:20:50.640 --> 00:20:54.920
<v Speaker 2>one framework directly inside another often leads to weird rendering issues, crashes,

430
00:20:55.039 --> 00:20:56.400
<v Speaker 2>or problems shutting down properly.

431
00:20:56.519 --> 00:20:58.759
<v Speaker 1>So what if you need parts built with different.

432
00:20:58.440 --> 00:21:01.880
<v Speaker 2>Toolkits, Launching them is completely separate windows? Maybe even separate

433
00:21:01.880 --> 00:21:03.680
<v Speaker 2>processes seems more stable?

434
00:21:03.759 --> 00:21:05.720
<v Speaker 1>And how would those separate windows talk to each other?

435
00:21:06.160 --> 00:21:09.720
<v Speaker 2>Back to our friend, the queue que shared cues are

436
00:21:09.720 --> 00:21:13.680
<v Speaker 2>presented again as a robust Pythonic way for independent GOI processes,

437
00:21:13.960 --> 00:21:16.640
<v Speaker 2>even if built with different frameworks, to pass messages or

438
00:21:16.720 --> 00:21:17.640
<v Speaker 2>data back and forth.

439
00:21:17.839 --> 00:21:20.480
<v Speaker 1>Okay, cool? What about going beyond two D? Does it

440
00:21:20.519 --> 00:21:21.759
<v Speaker 1>touch on three D graphics?

441
00:21:22.039 --> 00:21:25.880
<v Speaker 2>Yep? It introduces libraries for creating true three D scenes,

442
00:21:26.440 --> 00:21:29.920
<v Speaker 2>primarily PIOPENNGL, which is Python's binding to the standard open

443
00:21:29.920 --> 00:21:30.920
<v Speaker 2>geographics library.

444
00:21:30.960 --> 00:21:32.720
<v Speaker 1>You'll need to install that and PILT.

445
00:21:32.880 --> 00:21:36.279
<v Speaker 2>Pilot is often used alongside or instead of piopen gl

446
00:21:36.599 --> 00:21:39.799
<v Speaker 2>for handling window creation, event loops, and drawing shapes in

447
00:21:39.839 --> 00:21:42.839
<v Speaker 2>three D more easily. The book shows an example of

448
00:21:42.839 --> 00:21:45.480
<v Speaker 2>creating a spinning colored three D cube.

449
00:21:45.240 --> 00:21:48.440
<v Speaker 1>So you can actually control the three dview with keyboard input.

450
00:21:48.599 --> 00:21:51.480
<v Speaker 2>Yeah, you can capture keypresses within the pilot open gl

451
00:21:51.519 --> 00:21:54.400
<v Speaker 2>window and use them to trigger actions like rotating the

452
00:21:54.440 --> 00:21:56.279
<v Speaker 2>camera or the three D object.

453
00:21:56.440 --> 00:21:59.319
<v Speaker 1>Can these three D libraries create their own windows without

454
00:21:59.359 --> 00:22:01.440
<v Speaker 1>needing to kin wx.

455
00:22:01.160 --> 00:22:05.119
<v Speaker 2>Python, Yes, Absolutely, Pilot or even lower level open gl

456
00:22:05.240 --> 00:22:08.200
<v Speaker 2>utility libraries like glut can manage their own windows and

457
00:22:08.240 --> 00:22:11.079
<v Speaker 2>event loops, specifically for rendering the three D graphics and

458
00:22:11.160 --> 00:22:13.920
<v Speaker 2>handling input for that window. The book even shows simple

459
00:22:13.920 --> 00:22:15.000
<v Speaker 2>animation examples.

460
00:22:15.200 --> 00:22:17.400
<v Speaker 1>Okay, one quick step back to two D basics images

461
00:22:17.480 --> 00:22:19.480
<v Speaker 1>is to kiner good with images out of the box.

462
00:22:19.839 --> 00:22:23.000
<v Speaker 2>Uh not really. The built in kinter photo image is

463
00:22:23.000 --> 00:22:27.759
<v Speaker 2>surprisingly limited. It handles formats like GIF and PGMPPM, but

464
00:22:27.880 --> 00:22:30.359
<v Speaker 2>famously not common ones like JPEG or PNG.

465
00:22:30.599 --> 00:22:33.200
<v Speaker 1>Previously no JPEGs, nope to.

466
00:22:33.160 --> 00:22:36.079
<v Speaker 2>Display JPEGs, p and g S and other modern formats

467
00:22:36.079 --> 00:22:38.799
<v Speaker 2>in kinter, you pretty much need the Pillow library. It's

468
00:22:38.799 --> 00:22:42.240
<v Speaker 2>the modern successor to the old Python Imaging library PIL.

469
00:22:42.359 --> 00:22:44.920
<v Speaker 1>So you install pillow right PIP and sall pillow.

470
00:22:45.200 --> 00:22:47.759
<v Speaker 2>Then you use image tk dot photo image from the

471
00:22:47.839 --> 00:22:51.079
<v Speaker 2>PIL module. Yes, the import is still often PIL to

472
00:22:51.160 --> 00:22:53.640
<v Speaker 2>load your image file and that object can be used

473
00:22:53.680 --> 00:22:55.119
<v Speaker 2>in Kinder labels or buttons.

474
00:22:55.480 --> 00:22:57.920
<v Speaker 1>Got it. So Pillow is essential for real world image

475
00:22:57.920 --> 00:23:01.000
<v Speaker 1>handling and teeter that covers a mass of amount of ground,

476
00:23:01.000 --> 00:23:04.400
<v Speaker 1>from basic widgets to three D and databases. How does

477
00:23:04.440 --> 00:23:07.079
<v Speaker 1>the book tie this all together with advice on writing

478
00:23:07.119 --> 00:23:09.200
<v Speaker 1>good gy code best practices.

479
00:23:09.640 --> 00:23:13.200
<v Speaker 2>It definitely emphasizes writing code that's clean, maintainable, and extendable.

480
00:23:13.519 --> 00:23:16.359
<v Speaker 2>A big theme is avoiding spaghetti code. Spaghetti code, yeah,

481
00:23:16.400 --> 00:23:18.920
<v Speaker 2>you know, code that's all tangled up, jumps around unpredictably

482
00:23:18.920 --> 00:23:22.200
<v Speaker 2>with globals or complex logic flows, impossible to understand or

483
00:23:22.240 --> 00:23:26.200
<v Speaker 2>modify without breaking something. The opposite is modular, well structured code.

484
00:23:26.319 --> 00:23:29.279
<v Speaker 1>How do you achieve that structure in a bigger project

485
00:23:29.519 --> 00:23:30.640
<v Speaker 1>with multiple files?

486
00:23:30.880 --> 00:23:32.920
<v Speaker 2>The book mentions the role of in it dot pi

487
00:23:33.039 --> 00:23:36.799
<v Speaker 2>files in making directories into Python packages. It even shows

488
00:23:36.839 --> 00:23:40.319
<v Speaker 2>some techniques using CIS dot path or site dot ad,

489
00:23:40.359 --> 00:23:43.359
<v Speaker 2>site deer with an in dot PII to help Python

490
00:23:43.440 --> 00:23:46.160
<v Speaker 2>find your modules correctly, especially if you're running scripts from

491
00:23:46.160 --> 00:23:49.960
<v Speaker 2>different locations outside of IT, and the procedural versus OP

492
00:23:50.200 --> 00:23:53.839
<v Speaker 2>discussion comes back. The strong recommendation is for anything beyond

493
00:23:53.880 --> 00:23:57.039
<v Speaker 2>a very simple script, use object oriented programming. It just

494
00:23:57.079 --> 00:24:00.240
<v Speaker 2>scales better and makes maintenance feasible. Procedural is okay for

495
00:24:00.279 --> 00:24:01.119
<v Speaker 2>tiny utilities.

496
00:24:01.240 --> 00:24:04.160
<v Speaker 1>What about naming things, files, variables.

497
00:24:03.640 --> 00:24:08.480
<v Speaker 2>Functions meaningful names? This is stressed. Name your modules based

498
00:24:08.519 --> 00:24:11.839
<v Speaker 2>on what they do, like guywidgets dot PI or database

499
00:24:11.920 --> 00:24:15.839
<v Speaker 2>connector dot pi, not mod one dot PI or utilsnew

500
00:24:15.880 --> 00:24:19.519
<v Speaker 2>dot PI. Same for variables and functions. Make them descriptive,

501
00:24:19.799 --> 00:24:24.519
<v Speaker 2>avoid cryptic abbreviations. Consistency helps hugely, especially if you're working

502
00:24:24.559 --> 00:24:26.960
<v Speaker 2>in a team, but even just for your future self.

503
00:24:27.799 --> 00:24:30.599
<v Speaker 2>Design patterns also get a brief mention, like the factory

504
00:24:30.640 --> 00:24:33.839
<v Speaker 2>pattern as a way to handle more complex structural problems

505
00:24:34.000 --> 00:24:37.519
<v Speaker 2>like creating different variations of widgets systematically. It's more of

506
00:24:37.519 --> 00:24:40.519
<v Speaker 2>an introduction to the idea that these patterns exist to solve.

507
00:24:40.240 --> 00:24:43.759
<v Speaker 1>Common problems and just generally managing the complexity as you

508
00:24:43.799 --> 00:24:44.960
<v Speaker 1>add more and more features.

509
00:24:45.039 --> 00:24:49.519
<v Speaker 2>Yeah, it acknowledges GUIs naturally get complex. Practical tips include

510
00:24:49.720 --> 00:24:53.160
<v Speaker 2>using label frame containers to visually group related controls, using

511
00:24:53.200 --> 00:24:56.559
<v Speaker 2>loops to create multiple similar widgets instead of copy pasting code,

512
00:24:56.799 --> 00:25:00.519
<v Speaker 2>and organizing really large UIs into logical sections using TT

513
00:25:00.559 --> 00:25:03.200
<v Speaker 2>notebook tabs. These you are always to break down the complexity.

514
00:25:03.279 --> 00:25:05.759
<v Speaker 1>Wow. Okay, that really was a deep dive into this cookbook.

515
00:25:05.799 --> 00:25:08.680
<v Speaker 1>We've gone from literally the first import kinter and main

516
00:25:08.720 --> 00:25:09.599
<v Speaker 1>loop right.

517
00:25:09.519 --> 00:25:14.039
<v Speaker 2>Up to placing widgets, arranging them with grid sticky label frames.

518
00:25:13.720 --> 00:25:17.200
<v Speaker 1>Handling user input with string bars and callbacks, making things

519
00:25:17.240 --> 00:25:19.599
<v Speaker 1>responsive with threads and cues.

520
00:25:19.559 --> 00:25:23.200
<v Speaker 2>Connecting to my SQL databases, thinking about different languages with

521
00:25:23.279 --> 00:25:24.279
<v Speaker 2>I eighteen N.

522
00:25:24.400 --> 00:25:29.359
<v Speaker 1>And L ten N, testing with unit test, debugging, exploring

523
00:25:29.359 --> 00:25:33.039
<v Speaker 1>alternatives like wx Python, even touching on three D with

524
00:25:33.119 --> 00:25:35.440
<v Speaker 1>PIOPENNGL and PIGLT, and.

525
00:25:35.400 --> 00:25:38.920
<v Speaker 2>Finally wrapping up with best practices like OOP and good

526
00:25:39.000 --> 00:25:41.000
<v Speaker 2>naming to avoid that spaghetti code.

527
00:25:41.039 --> 00:25:43.680
<v Speaker 1>This book seems to lay out a really comprehensive path

528
00:25:43.759 --> 00:25:46.799
<v Speaker 1>full of practical examples. It shows Python's power, but also

529
00:25:46.839 --> 00:25:49.920
<v Speaker 1>points out where you need extra libraries like pillow or pits.

530
00:25:50.119 --> 00:25:52.319
<v Speaker 2>Yeah, it gives a solid map of the territory for

531
00:25:52.400 --> 00:25:56.079
<v Speaker 2>building desktop applications with Python. GUIs covering a lot of

532
00:25:56.079 --> 00:25:57.480
<v Speaker 2>the common challenges you'd encounter.

533
00:25:57.759 --> 00:26:00.680
<v Speaker 1>So having surveyed this whole landscape, from the cops button

534
00:26:00.759 --> 00:26:04.079
<v Speaker 1>to networked, database driven apps and even three D, it

535
00:26:04.200 --> 00:26:07.359
<v Speaker 1>makes you wonder, for you listening, what kind of GUI challenge,

536
00:26:07.400 --> 00:26:09.839
<v Speaker 1>maybe something you've seen elsewhere or thought about building, are

537
00:26:09.880 --> 00:26:12.519
<v Speaker 1>you now most curious to try and tackle using Python
