Found 605 Articles for Tkinter

How to Change the position of MessageBox using Python Tkinter

Dev Prakash Sharma
Updated on 04-Mar-2021 13:58:35

1K+ Views

Let us suppose that we want to create a dialogue box using tkinter. To create the dialogue box we can use the MessageBox library which contains several functions to quickly create dialogue types.To adjust the position of the created Dialogue Box, we can use its “toplevel” property which basically gives the priority to the current box and keeps all the other processes in the backend.It contains some other functions like title, message, and details. To change the position of the MessageBox widget, we will use geometry method.Example#import the tkinter library from tkinter import * #define the messagebox function ... Read More

How to center an image in canvas Python Tkinter

Dev Prakash Sharma
Updated on 04-Mar-2021 13:56:43

3K+ Views

Let us consider that we are creating a GUI-based application using Tkinter and we want to load an image in the Tkinter canvas.By default, the canvas loads the images according to its width and height. However, we can manipulate the position of an image in any direction (N, S, E, W, NS, EW, etc.) by passing the ‘Direction’ value in the anchor parameter. An anchor is a parameter which is invoked along with the image function; it defines the direction or position of the image in the canvas.By using anchor parameters, we can align the text and images in any ... Read More

How to add placeholder to an Entry in tkinter?

Dev Prakash Sharma
Updated on 04-Mar-2021 13:55:10

4K+ Views

Tkinter provides features to add widgets such as button, text, entry, dialogue and other attributes that help to develop an application. However, tkinter doesn't include a placeholder in the entry widget. Placeholders are the dummy text that appears in the entry widget to inform the user about it.In this article, we will add a placeholder in the entry widget using the insert(default value, text) function that takes a default value such as 0 along with the placeholder text.Example#Import tkinter library from tkinter import* #Create an instance of frame win= Tk() #Set geometry win.geometry("700x400") #Create a text Label ... Read More

How to add padding to a tkinter widget only on one side?

Dev Prakash Sharma
Updated on 04-Mar-2021 13:53:53

6K+ Views

Let us suppose that we want to add padding on one side (either top/bottom or left/right) of a particular widget. We can achieve this in Tkinter by using its pack() and grid() methods.In pack() method, we have to define the value for “padx” and “pady”. On the other hand, the grid method requires only two tuples, i.e., x and y for adding padding around either of X-axis or Y-axis.Example#import the required library from tkinter import * #Create an instance of window or frame win= Tk() win.geometry("700x400") #Create two buttons #Add padding in x and y axis b1= ... Read More

How do you run your own code alongside Tkinter's event loop?

Dev Prakash Sharma
Updated on 04-Mar-2021 13:52:39

1K+ Views

Tkinter is widely used to create and develop GUI based applications and games. Tkinter provides its window or frame where we execute our programs and functions along with other attributes.Let us consider that we are working with a particular application and we want to write the changes in the code while running the application. Tkinter provides a callback method which can be used to run the window while iterating over it. We can keep running the window using the after(duration, task) method that will basically run the changes after a duration.In this example, we will create a window which prints ... Read More

How do I get rid of the Python Tkinter root window?

Dev Prakash Sharma
Updated on 04-Mar-2021 13:50:14

8K+ Views

Sometimes, while testing a Tkinter application, we may need to hide the Tkinter default window or frame. There are two general methods through which we can either hide our Tkinter window, or destroy it.The mainloop() keeps running the Tkinter window until it is not closed by external events. In order to destroy the window we can use the destroy() callable method.However, to hide the Tkinter window, we generally use the “withdraw” method that can be invoked on the root window or the main window.In this example, we have created a text widget and a button “Quit” that will close the ... Read More

How do I close a tkinter window?

Dev Prakash Sharma
Updated on 04-Mar-2021 13:46:19

11K+ Views

Creating an application using tkinter is easy but sometimes, it becomes difficult to close the window or the frame without closing it through the button on the title bar. In such cases, we can use the .destroy() method to close the window.As tkinter attributes are independent of each other, we can create a separate method to close the window using a button.Example#Import the library from tkinter import * #Create an instance of window win = Tk() #Set the geometry of the window win.geometry("700x400") #Define a function to close the window def close_win():    win.destroy() #Create a ... Read More

Good example of functional testing a Python Tkinter application

Dev Prakash Sharma
Updated on 04-Mar-2021 13:43:10

2K+ Views

Let us suppose that we have a GUI-based Python tkinter application that takes the text input from the user and validates by saving it in a new text file. The file contains the same text input that the user has typed. We can check and validate the user input from the file.In Functional Testing, we are primarily concerned about backend API, database, user-server communication, Input and output, etc.To check the application using the functional testing strategy, we have to first understand the user requirement and the input/output. After testing the pre-phase, we test our application for different test cases.For example, ... Read More

Dynamically Resize Buttons When Resizing a Window using Tkinter

Dev Prakash Sharma
Updated on 04-Mar-2021 13:40:59

1K+ Views

Python has many rich libraries for creating and developing GUI-based applications. Tkinter is one of the most commonly used Python libraries for creating GUI-based applications. It has many features like adding widgets and other necessary attributes necessary for creating an application.A button is a widget which can be assigned for some particular task or event. However, to dynamically resize or position the button widget, we can configure its position and layout using the Grid module in tkinter. To resize the button dynamically, we can use rowconfiguration() and coloumnconfiguration() methods.In a tkinter Grid system, there are four attributes which can be ... Read More

Creating a Transparent window in Python Tkinter

Dev Prakash Sharma
Updated on 04-Mar-2021 13:39:00

715 Views

Python is the most popular language for developing and creating functional and desktop applications. It has a rich library of different modules and functions which provides extensibility and accessibility to create and develop applications.Tkinter is the most commonly used library for creating GUI-based applications. It has features like adding widgets and other necessary attributes.Let us suppose that we want to create a transparent window using tkinter. To create the transparent window, we can use the attributes property and define the opacity value.Example#Importing the tkinter library from tkinter import * #Create an instance of tkinter frame win= Tk() #Define ... Read More

Advertisements