Found 310 Articles for GUI-Programming

How to open multiple filenames in Tkinter and add the file names to a list?

Dev Prakash Sharma
Updated on 18-Jun-2021 13:24:44

3K+ Views

To open a file dialog in a tkinter application, tkinter provides the tkfiledialog package which creates a dialog box to interact with the external files located on the system. In order to work with filedialog, we have to first import the package using the following command, import tkinter.filedialog as fdTo open the explorer in the window, use asopenfilename(parent, title, **options) function. It will just pull the window and allow the user to select the file from the explorer. Once the file has been opened, we can define a function to print the list of all the selected files.Example# Import the required libraries ... Read More

How to create a directly-executable cross-platform GUI app using Python(Tkinter)?

Dev Prakash Sharma
Updated on 18-Jun-2021 13:13:32

1K+ Views

Python is a programming language which can be used to create cross-platform applications that are supported in various operating systems such as Microsoft Windows, Mac OS, and Linux.To create a GUI-based application, we can use the Tkinter library. However, Python provides different modules and extensions which convert a program into an executable application.For Windows executables - PyInstaller, py2exeFor Linux executables - FreezeFor Max executables - py2appExampleFor this example, we will first install the PyInstaller module using pip in our Windows operating system. The module can be installed by using the command, pip install pyInstallerUsing this module, we will convert our application into ... Read More

How to read multiple text files from a folder in Python?(Tkinter)

Dev Prakash Sharma
Updated on 18-Jun-2021 13:12:49

7K+ Views

Python is capable of handling files, objects, and creating different applications. We can use Python's extensions and packages to build and develop fully featured applications.Suppose you want to control the files in your system; then Python provides an OS Module which has system-enabled functionalities to allow you interact with the files in the operating system.Let us see how we can read multiple text files from a folder using the OS module in Python.Import the OS module in your notebook.Define a path where the text files are located in your system.Create a list of files and iterate over to find if ... Read More

How do I get the background color of a Tkinter Canvas widget?

Dev Prakash Sharma
Updated on 08-Jun-2021 10:14:06

2K+ Views

Tkinter canvas widget is used for many different purposes such as adding objects, drawing shapes, images and complex visuals to a graphical interface in an application. We can also configure its style such as background color, foreground color, and other properties using the configure properties or passing attributes.Suppose we want to inherit the background color of the Canvas widget in another widget or in some part of the application. This can be achieved by using my_canvas["background"] property. Further, we can use canvas["background"] to fetch the background color of the canvas widget.Example# Import the required library from tkinter import * from ... Read More

How to remove Ttk Notebook Tab Dashed Line? (tkinter)

Dev Prakash Sharma
Updated on 08-Jun-2021 10:12:19

734 Views

In order to work with Tabs and separate your workflow in an application, Tkinter provides a Notebook widget. We can use the Notebook widget to create Tabs in an application. Tabs are useful to isolate one particular frame or event from another.Generally, Notebook widget can be configured and styled using the ttk themed widget. So, to style a Notebook widget, we pass TNotebook and TNotebook.Tab parameters in the configuration. If we click on a particular Tab, there may appear some rectangular dashed line which can be removed.Example# Import the required library from tkinter import * from tkinter import ttk ... Read More

How to use rgb color codes in tkinter?

Dev Prakash Sharma
Updated on 08-Jun-2021 10:09:02

5K+ Views

Tkinter has many inbuilt features and attributes that help the application developer to build a robust and featured application. We can set the attributes such as background color, foreground color, and other properties of a widget using the configure method in Tkinter.To set the background color or foreground color of a widget, we can use both default and RGB color codes. RGB is defined by the 6 digit alphanumeric character containing different digits of R, G, B values. In order to use RGB color codes in tkinter, we have to define it using the format #aab123.Example# Import the required libraries ... Read More

How to bind the Escape key to close a window in Tkinter?

Dev Prakash Sharma
Updated on 08-Jun-2021 10:06:45

5K+ Views

Tkinter Events are very useful for making an application interactive and functional. It provides a way to interact with the internal functionality of the application and helps them to rise whenever we perform a Click or Keypress event.In order to schedule the events in tkinter, we generally use the bind('Button', callback) method. We can bind any key to perform certain tasks or events in the application. To bind the Esc key such that it will close the application window, we have to pass the Key and a callback event as the parameter in the bind(key, callback) method.Example# Import the required ... Read More

How to create a modal dialog in tkinter?

Dev Prakash Sharma
Updated on 08-Jun-2021 10:04:45

5K+ Views

Dialog Boxes are a very essential component of any application. It is generally used to interact with the user and the application interface. We can create dialog boxes for any tkinter application using the Toplevel window and other widgets. The toplevel window pops up the stuff above all the other windows. Thus, we can add more stuff on the toplevel window for building dialog boxes.ExampleIn this example, we have created a modal dialog which has two parts, Initialization of the Toplevel window.Function Definition for Popup Dialog Event.Adding widgets in the Toplevel window.Function Definition for Dialog options.# Import required libraries from ... Read More

How to clear items from a ttk.Treeview widget?

Dev Prakash Sharma
Updated on 08-Jun-2021 10:01:04

8K+ Views

Generally, Tkinter treeview widget is used to draft or construct tables for the given data points in the input. We can even add items in the treeview widget to maintain a nested list in an application. If we want to remove or clear all the items in a given treeview widget, then we have to first select all the items present in the treeview widget using get_children() method.Once we have selected all the treeview items programmatically, then we can delete the items using delete(item) method. In order to get all the children, we can use the delete() method inside a loop.Example# ... Read More

How to show and hide widgets in Tkinter?

Dev Prakash Sharma
Updated on 08-Jun-2021 09:57:23

14K+ Views

Tkinter is a Python library which is used to create and develop GUI-based applications.Let us suppose that we have to create an application such that we can show or hide the widgets.In order to display/show the widget, use pack() geometry managerTo hide any widget from the application, use pack_forget() method.ExampleLet us take this example to understand how to show/hide widgets −# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win = Tk() # Set the size of the tkinter window win.geometry("700x350") # Define the style for ... Read More

Advertisements