

cursor: This sets the cursor used when the cursor is on the canvasĭ. bg: We give the background color of the canvas to this parameterĬ. bd: This parameter sets the border width. The parent window is given as the parameter master. This lets you draw shapes such as lines, polygons, etc., and other layouts like graphics, text, and widgets. ("Greetings","Hello! Welcome to PythonGeeks.")ītn=Button(win,text="Click Me", width=10,height=5,command=func) Win.title('Welcome') #setting title of the window Win=Tk() #creating the main window and storing the window object in 'win' Now let us see an example of creating a button.Įxample of the button import ssagebox height: This sets the height of the button to the given value width: This sets the width of the button to the given value image: This parameter sets the background of the button to the image given font: This parameter sets the font style of the label of the buttonį.
#VANS PYTHON RUNNER CODE#
This function contains the code to set the functionality of the button.Į. command: We give a function to this parameter. bg: We give the background color of the button to the parameterĭ. activeforeground: This parameter sets the foreground color when the cursor is on the buttonĬ. activebackground: This parameter sets the background color when the cursor is on the buttonī. Besides this, we have many other parameters that set the features of the button. The parent window is given as the master. To add a button to the window, we use the Button() method. place(): This method organizes the widgets by placing them in the position mentioned in the code. grid(): This method organizes widgets in the grid or table form before positioning the parent widgetģ. pack(): This method organizes widgets in blocks before positioning the parent widgetĢ. Before discussing the widgets let us use functions offered by Tkinter to organize these widgets.ġ. Win.geometry('500x200') #setting the size of the windowĪs said before we have 19 widgets in the Tkinter library which include text fields, labels, buttons, etc. We can also set the size of the window by using the geometry() function. Let us discuss the widgets in the next section. We can see a blank window as we did not add any widgets. Win.mainloop() #running the loop that works as a trigger Win=tkinter.Tk() #creating the main window and storing the window object in 'win' Now let us see the code to build a simple GUI.Įxample of creating a GUI window: import tkinter This is an infinite loop that runs till we close the application window. This is the function that gets triggered when an event occurs. We will discuss each of these in the next section.

Adding the required widgets to the window: This function returns the main window object which can be used in the next steps. We can change the name of the window by setting the className argument to your choice. The syntax of the Tk() function is: Tk(screenName=None, baseName=None, className=’Tk’, useTk=1)Īll the arguments are optional. To create the main GUI window using the function Tk() function. Creating the main window for the application: We can import the Tkinter library by writing the below code. This process of creating a simple GUI in Tkinter requires the following steps: 1. The creation of a blank GUI interface is the first step of the creation of any GUI. It is a faster and easier way to build a GUI in Python. It provides an object-oriented interface to build the Tk GUI toolkit. Tkinter is a standard Python library used for GUI programming. Python Tkinter ModuleĪs said before we will concentrate on the Tkinter module. WxPython is also a cross-platform GUI toolkit. Qt is a C++ framework that is used by Python to implement a cross-platform PyQt toolkit as a plug-in. PyQt is a Python toolkit binding of the Qt toolkit. This is built on top of the Tk interface. Tkinter is a standard package used for GUI programming in Python.

We can use any of the following toolkits in Python for GUI programming. Let us start by seeing different modules Python offers. Then we will discuss the Tkinter, one of the most commonly used modules, in detail. We will see different toolkits that Python provides for GUI programming. In this article, we will learn to make GUIs using Python.
These are the elements that form the GUI (Graphical User Interface). One common thing you observe in all the applications is that they have multiple components like labels, fields to give inputs, buttons, etc. You would have used a lot of applications.
