Found 604 Articles for Tkinter

How to Move an Image in Tkinter canvas with Arrow Keys?

Dev Prakash Sharma
Updated on 18-Jun-2021 13:23:43

4K+ Views

Tkinter Canvas widget is one of the versatile widgets in the Tkinter library. It is used to create different shapes, images, and animating objects. We can provide a dynamic attribute to the image defined in a Canvas widget by using the move() method.Define the image and the coordinates as a parameter in the move(Image, x, y) method to move the Image in the Canvas. We declare images globally in order to track the Image location in the Canvas.We can follow these steps to make our image movable within the canvas, First, define the Canvas widget and add images to it.Define the move() function ... Read More

How to move a Tkinter canvas with Mouse?

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

4K+ Views

Tkinter Canvas widget is one of the versatile widgets in the Tkinter library. It is used to create different shapes, images, and animating objects. We can move images in a particular direction on the Canvas widget using the move() method.Define the image and the coordinates as a parameter in the move(Image, x, y) method to move the object in the Canvas. We declare images globally in order to move or change the position.We can follow these steps to allow our image to move within the canvas, First, define the Canvas widget and add images to it.Define the move() function to allow ... Read More

How to display a Listbox with columns using Tkinter?

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

5K+ Views

To deal with lots of data in any application, Tkinter provides a Treeview widget. It has various features such as displaying data in the form of tables consisting of Rows and Columns.Treeview widget enables the user to add tables, insert data into it, and manipulate the data from the table. The Treeview widget can be constructed by defining the Treeview(parent, column, **options) constructor.Example# 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") s = ttk.Style() ... Read More

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

735 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

Advertisements