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 built-in Python tkinkter library.
How to do it…
Having searched online and read the documentation, we might start by writing the following code to create our GUI:
GUI_Spaghetti.py
# 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=' Type into the scrolled text
control: ')
scr=tkinter.scrolledtext.ScrolledText(outputFrame,width=scrolW,height=scrolH,wrap=tkinter.WORD)
e='E'
scr.grid(column=1,row...