O'Reilly logo

Python GUI Programming Cookbook by Burkhard A. Meier

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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=' ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required