Found 310 Articles for GUI-Programming

How to bind all the number keys in Tkinter?

Dev Prakash Sharma
Updated on 22-Dec-2021 10:51:17

1K+ Views

While developing a Tkinter application, we often encounter cases where we have to perform some specific operation or event with the keystrokes (on keyboard). Tkinter provides a mechanism to deal with such events.You can use bind(, callback) function for each widget that you want to bind in order to perform a certain type of event. Whenever we bind a key with an event, the callback event occurs whenever a corresponding key is pressed.ExampleLet's consider an example. Using the bind("", callback) function, we can also bind all the number keys to display a message on the screen such that whenever a ... Read More

How to make specific text non-removable in tkinter?

Dev Prakash Sharma
Updated on 22-Dec-2021 10:49:40

140 Views

In Tkinter, users can input text using two basic text input widgets − the Text widget and the Entry widget. The Text widget is generally used to accept multiline user input, whereas in an Entry widget, the user can type only singleline text.You can customize these widgets and add additional functionality using built-in library functions and methods. To validate the input in an Entry widget, you can use the register() method. This method returns a string that can be used to call the function at later stages.To validate the input in an Entry widget, use the config(**options) method and pass ... Read More

How to show multiple Canvases at the same time in Tkinter?

Dev Prakash Sharma
Updated on 22-Dec-2021 10:47:51

2K+ Views

The Canvas widget is one of the versatile widgets in Tkinter which is used to create illustrations, draw shapes, arcs, images, and other complex layouts in an application. To create a Canvas widget, you'll need to create a constructor of canvas(root, **options).You can use the factory functions to create text, images, arcs and define other shapes in the canvas. In some cases, if you want to create another canvas using the same canvas to keep the application workflow consistent, then you can create a button to call an event that creates another canvas.To understand this, let us create a canvas ... Read More

Getting the Cursor position in Tkinter Entry widget

Dev Prakash Sharma
Updated on 22-Dec-2021 10:46:22

3K+ Views

We are already familiar with input forms where various single Entry fields are created to capture the user input. With Tkinter, we can also create a single input field using the Entry widget. Each character in the Entry field that the user enters is indexed. Thus, you can retrieve this index to get the current position of the cursor by using the index() method. To retrieve the current location of the cursor, you can pass the INSERT argument in this function.Example# Import required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter window ... Read More

How to specify the file path in a tkinter filedialog?

Dev Prakash Sharma
Updated on 22-Dec-2021 10:44:18

4K+ Views

Tkinter offers several built-in functions and class library methods to build components and user-actionable items of an application. filedialog is one of the tkinter modules that provides classes and library functions to create file/directory selection windows. You can use filedialog where you need to ask the user to browse a file or a directory from the system.You can also specify the location of the directory from where a particular file should be picked up. To display the filedialog that starts from a particular location, use the initialdir = argument in the static factory function askopenfilename(initialdir=). This function creates a ... Read More

How to set padding of all widgets inside a window or frame in Tkinter?

Dev Prakash Sharma
Updated on 22-Dec-2021 10:42:47

4K+ Views

Padding enhances the layout of the widgets in an application. While developing an application in Tkinter, you can set the padding in two or more ways. The geometry manager in Tkinter allows you to define padding (padx and pady) for every widget (label, text, button, etc). To set the application component and its properties look and feel consistent, you can define the values in a variable. The values can be further used to define the padding of the widgets. Let us understand this with an example.ExampleIn the following example, we will create a frame inside which the widgets are defined. ... Read More

How to close only the TopLevel window in Python Tkinter?

Dev Prakash Sharma
Updated on 22-Dec-2021 10:40:56

2K+ Views

The Toplevel window is an option to create a child window in an application. It works similar to the default main tkinter window. We can configure the size of a Toplevel window, customize its properties and attributes as well as add widgets that we want to build the component with.For a particular application, if we have defined a Toplevel window, then we can close it using the destroy() method.ExampleIn the following example, we have created an application that contains a button to open a Toplevel window. The Toplevel window or child window contains a label text and a button to ... Read More

Difference between .pack and .configure for widgets in Tkinter

Dev Prakash Sharma
Updated on 22-Dec-2021 10:39:18

792 Views

We use various geometry managers to place the widgets on a tkinter window. The geometry manager tells the application where and how to organize the widgets in the window. With geometry manager, you can configure the size and coordinates of the widgets within the application window.The pack() method in tkinter is one of the three geometry managers. The other geometry managers are grid() and place(). The pack() geometry manager is commonly used to provide padding and a way to arrange the widgets in the window.To configure the properties and attributes of a widget explicitly after defining it, you can use ... Read More

Python Tkinter – How to export data from Entry Fields to a CSV file?

Dev Prakash Sharma
Updated on 22-Dec-2021 10:37:34

4K+ Views

The Entry widget is used to accept single-line text strings from users.Text widget − Displays multiple lines of text that can be edited.Label widget − Displays one or more lines of text that cannot be modified by the user.Importing tkinter, csv and creating the main window. Name the output window "Data Entry"(any name for output window) and Create three functions based on the output you need. Here the function of add, save and clear is built in to make the buttons work functionally.After providing the input in the window, click the add button. The add function will display a message ... Read More

How do I paste the copied text from the keyboard in Python?

Dev Prakash Sharma
Updated on 22-Dec-2021 12:56:37

750 Views

Python offers many built-in libraries and modules which provides a way to implement the additional features in developing various python applications. pyperclip is one of the cross-platform python modules to implement the copyandpaste operation in any Python application. To use it in Python application, you've to install it using the following command, pip install pyperclipThe practical use-case can be implemented by developing an application which copies the text from the clipboard and displays on the screen. Additionally, we can also display the copied text in an Entry widget or Text widget which accepts the user input in the form of ... Read More

Advertisements