Avoiding spaghetti code
In this recipe, we will explore a typical way to create spaghetti code and then we will see a much better way of how to avoid such code.
Note
Spaghetti code is code in which a lot of functionality is intertangled.
Getting ready
We will create a new, simple GUI written in Python using the tkinter built-in Python library.
How to do it...
Having searched online and read the documentation, we might start by writing the following code to create our GUI:
# Spaghetti Code ############################# def PRINTME(me):print(me) import tkinter x=y=z=1 PRINTME(z) from tkinter import * scrolW=30;scrolH=6 win=tkinter.Tk() if x:chVarUn=tkinter.IntVar() from tkinter import ttk WE='WE' import tkinter.scrolledtext outputFrame=tkinter.ttk.LabelFrame(win,text=' ...
Get Python GUI Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.