Book Image

Python GUI Programming Cookbook

By : Burkhard Meier
Book Image

Python GUI Programming Cookbook

By: Burkhard Meier

Overview of this book

Table of Contents (18 chapters)
Python GUI Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

When not to use OOP


Python comes built-in with object-oriented programming capabilities, but at the same time, we can write scripts that do not need to use OOP.

For some tasks, OOP does not make sense.

This recipe will show when not to use OOP.

Getting ready

In this recipe, we will create a Python GUI similar to previous recipes. We will compare the OOP code to the non-OOP alternative way of programming.

How to do it...

Let's first create a new GUI using OOP methodology. The following code will create the GUI displayed below the code:

import tkinter as tk
from tkinter import ttk
from tkinter import scrolledtext
from tkinter import Menu

class OOP():
    def __init__(self): 
        self.win = tk.Tk()         
        self.win.title("Python GUI")      
        self.createWidgets()

    def createWidgets(self):    
        tabControl = ttk.Notebook(self.win)     
        tab1 = ttk.Frame(tabControl)            
        tabControl.add(tab1, text='Tab 1')    
        tabControl.pack(expand=1, fill...