Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python GUI Programming Cookbook

You're reading from   Python GUI Programming Cookbook Over 80 object-oriented recipes to help you create mind-blowing GUIs in Python

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher
ISBN-13 9781785283758
Length 350 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Burkhard Meier Burkhard Meier
Author Profile Icon Burkhard Meier
Burkhard Meier
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Creating the GUI Form and Adding Widgets FREE CHAPTER 2. Layout Management 3. Look and Feel Customization 4. Data and Classes 5. Matplotlib Charts 6. Threads and Networking 7. Storing Data in Our MySQL Database via Our GUI 8. Internationalization and Testing 9. Extending Our GUI with the wxPython Library 10. Creating Amazing 3D GUIs with PyOpenGL and PyGLet 11. Best Practices Index

Preventing the GUI from being resized

Getting ready

This recipe extends the previous one. Therefore, it is necessary to have typed Recipe 1 yourself into a project of your own or downloaded the code from https://www.packtpub.com/support.

How to do it...

We are preventing the GUI from being resized.

import tkinter as tk        # 1 imports

win = tk.Tk()               # 2 Create instance
win.title("Python GUI")     # 3 Add a title       
    
win.resizable(0, 0)         # 4 Disable resizing the GUI

win.mainloop()              # 5 Start GUI

Running the code creates this GUI:

How to do it...

How it works...

Line 4 prevents the Python GUI from being resized.

Running this code will result in a GUI similar to the one we created in Recipe 1. However, the user can no longer resize it. Also, notice how the maximize button in the toolbar of the window is grayed out.

Why is this important? Because, once we add widgets to our form, resizing can make our GUI look not as good as we want it to be. We will add widgets to our GUI in the next recipes.

Resizable() is a method of the Tk() class and, by passing in (0, 0), we prevent the GUI from being resized. If we pass in other values, we hard-code the x and y start up size of the GUI, but that won't make it nonresizable.

We also added comments to our code in preparation for the recipes contained in this book.

Note

In visual programming IDEs such as Visual Studio .NET, C# programmers often do not think of preventing the user from resizing the GUI they developed in this language. That creates inferior GUIs. Adding this one line of Python code can make our users appreciate our GUI.

You have been reading a chapter from
Python GUI Programming Cookbook
Published in: Dec 2015
Publisher:
ISBN-13: 9781785283758
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime