| 173 | |
| 174 | |
| 175 | def main(): |
| 176 | global root, descTextarea, programListbox, undoChangesBtnSV, undoChangesButton |
| 177 | root = Tk() |
| 178 | root.title('Python Games by Example ' + __version__) |
| 179 | |
| 180 | mainframe = ttk.Frame(root, padding='5 5 12 12') |
| 181 | mainframe.grid(column=0, row=0, sticky=(N, W, E, S)) |
| 182 | mainframe.columnconfigure(0, weight=1) |
| 183 | mainframe.rowconfigure(0, weight=1) |
| 184 | |
| 185 | scrollbar = Scrollbar(mainframe, orient="vertical") |
| 186 | |
| 187 | # Remove the "pygame_games/" part of the filename for the purposes of listing games in the listbox. |
| 188 | programNamesInListbox = [d['filename'][len('pygame_games/'):] if 'pygame_games/' in d['filename'] else d['filename'] for d in PROGRAMS] |
| 189 | #programNamesInListbox.sort() # Re-alphabetize them. |
| 190 | |
| 191 | filenameSV = StringVar(value=programNamesInListbox) |
| 192 | programListbox = Listbox(mainframe, listvariable=filenameSV, yscrollcommand=scrollbar.set) |
| 193 | programListbox.grid(column=0, row=0, sticky=(N, S, E, W)) |
| 194 | programListbox.bind('<<ListboxSelect>>', programSelect) |
| 195 | |
| 196 | scrollbar.config(command=programListbox.yview) |
| 197 | scrollbar.grid(column=1, row=0, sticky=(N, S, E, W)) |
| 198 | |
| 199 | openFolderButton = ttk.Button(mainframe, text='Open Folder', command=openFolderClick) |
| 200 | openFolderButton.grid(column=0, row=1, stick=(N, S, E, W)) |
| 201 | |
| 202 | descTextarea = Text(mainframe, width=60, height=6) |
| 203 | descTextarea.grid(column=2, row=0, columnspan=3, sticky=(N, S, E, W)) |
| 204 | descTextarea.configure(font=('Arial', 12)) |
| 205 | descTextarea.configure(state='disabled') |
| 206 | |
| 207 | runButton = ttk.Button(mainframe, text='Run', command=runClick) |
| 208 | runButton.grid(column=2, row=1, sticky=(E, W)) |
| 209 | |
| 210 | viewSourceButton = ttk.Button(mainframe, text='View Source', command=viewSourceClick) |
| 211 | viewSourceButton.grid(column=3, row=1, sticky=(E, W)) |
| 212 | |
| 213 | undoChangesBtnSV = StringVar(value='Undo Changes') |
| 214 | undoChangesButton = ttk.Button(mainframe, textvariable=undoChangesBtnSV, command=undoChangesClick) |
| 215 | undoChangesButton.grid(column=4, row=1, sticky=(E, W)) |
| 216 | |
| 217 | blueUnderlineFont = font.Font(family='Helvetica', size=12, underline=True) |
| 218 | linkLabel = ttk.Label(mainframe, text='Learn to program at https://inventwithpython.com', font=blueUnderlineFont) |
| 219 | linkLabel.configure(foreground='blue', font=blueUnderlineFont) |
| 220 | linkLabel.grid(column=0, row=2, columnspan=4, sticky=(E, W)) |
| 221 | linkLabel.bind("<Button-1>", openInventWithPythonWebpage) |
| 222 | |
| 223 | # Add the padding around the widgets: |
| 224 | for child in mainframe.winfo_children(): |
| 225 | if child in (programListbox, scrollbar): |
| 226 | child.grid_configure(padx=0, pady=5) |
| 227 | elif child in (linkLabel,): |
| 228 | child.grid_configure(padx=5, pady=0) |
| 229 | else: |
| 230 | child.grid_configure(padx=5, pady=5) |
| 231 | |
| 232 | # Select a random item in the list box by default so that it's not |