Python GUI To develop GUI application in Python, there are multiple options in terms of python packages. The most generally used package is tkinter. In this Python GUI Tutorial, we will use tkinter to learn how to develop GUI applications. As a Python developer, sooner or later you’ll want to write an application with a graphical user interface.Fortunately, there are a lot of Python GUI options: The Python wiki on GUI programming lists over 30 cross-platform frameworks, as well as Pyjamas, a tool for cross-browser Web development based on a port of the Google Web Toolkit.
- [Instructor] Hi, and welcome to section one,GUI in Python.In this section, we are developing our first GUI in Python.We will create a working GUI applicationthat consists of labels, buttons, text boxes,combo boxes, check buttons in various statesas well as radio buttonsthat change the background color of the GUI.
In this video, we're going to create our first GUI.Then, we'll prevent it from being resized.Python is a very powerful programming language.It ships with the built-in Tkinter module.In only a few lines of code, four to be precise,we can build our first Python GUI.To follow this video,a working Python development environment is a prerequisite.The IDLE GUI that ships with Python is enough to start.
IDLE was built using Tkinter.In this video, we'll be using Atom.Cool, let's jump right in.Here are the four lines of Python code requiredto create the resulting GUI.On the first line, we import the built-in Tkinter moduleand alias it as tk to simplify our Python code.In line two, we create an instance of the tk classby calling its constructor, the parenthesesappended to Tk, turn the class into an instance.
We are using the alias tkso we don't have to use the longer word Tkinter.We are assigning the class instanceto a variable named win, short for window.As Python is a dynamically-typed language,we did not have to declare this variablebefore assigning to it.And we did not have to give it a specific type.Python infers the type from the assignment of the statement.Python is a strongly-typed language,so every variable always has a type.
We just don't have to specify its type beforehandlike in other languages.This makes Python a very powerfuland productive language to program in.In line three, we use the instance variableof the class win to give our window a titlevia the title property.In line four, we start the windows event loopby calling the mainloop method on the class instance win.
Up to this point in our code,we created an instance and set one property,but the GUI will not be displayeduntil we start the main event loop.Okay, let's execute this code.The filename is FirstGUI.py.Here's our first ever GUI.Cool, isn't it?Please note that in this filewe used a minimum amount of Python codeto create our first GUI program.However, throughout this course,we will use object-oriented programmingwhen it makes sense.
Okay, let's now move on to preventing the GUIfrom being resized.How do we do that?Well, here's another file named NotResizable.py.This file extends the previous one.What is different then?Line four prevents the Python GUI from being resized.Running this code will result in a GUIsimilar to the one we created just now.Let's see the output.As you can see, the user can no longer resize it.
Also, notice how the maximum buttonin 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 goodas we want it to be.We will add widgets to our GUI in the next videos.Resizable is a method of the tk class,and by passing in (0,0), we prevent the GUIfrom being resized.
Python Gui Builder
If we pass other values, we hardcode the Xand Y startup size of the GUI,but that won't make it non-resizable.Nice, we created our first ever GUI in this video.In the next one, we'll add a label to our form.