Dev Prakash Sharma

Dev Prakash Sharma

414 Articles Published

Articles by Dev Prakash Sharma

Page 8 of 42

How to hide and show canvas items on Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 19-Jun-2021 4K+ Views

The Canvas widget is one of the versatile widgets in Tkinter. It is used in many applications for designing the graphical user interface such as designing, adding images, creating graphics, etc. We can add widgets in the Canvas widget itself. The widgets that lie inside the canvas are sometimes called "Canvas Items".If we want to show or hide the canvas items through a Button, then this can be achieved by using the "state" property in itemconfig(id, state) method.ExampleIn this example, we will add an image in the canvas and a button will be used to show/hide the image in the ...

Read More

How do I get the index of an item in Tkinter.Listbox?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 19-Jun-2021 5K+ Views

We use the Tkinter Listbox widget to create a list of items. Each item in the listbox has some indexes that are assigned to them sequentially in vertical order.Let us suppose that we want to get the index of a clicked item in the listbox. Then, we have to first create a button that will capture the current selection of the items using list.curselection() method and then, we will print the index using the get() method.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win = Tk() # Set the size ...

Read More

How do I center the text in a Tkinter Text widget?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 19-Jun-2021 20K+ Views

Tkinter text widget is a multiline text input widget. It is used to insert, delete, and add textual data in the input field. It provides many built-in functions and attributes in its widget class.To configure and align the text at the CENTER of a Tkinter Text widget, we can use justify=CENTER property.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x350") text=Text(win) # Configure the alignment of the text text.tag_configure("tag_name", justify='center') # Insert a Demo Text text.insert("1.0", "How do ...

Read More

Difference between title() and wm_title() methods in Tkinter class

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 19-Jun-2021 1K+ Views

Tkinter has a definite class hierarchy which contains many functions and built-in methods. As we create applications, we use these functions to build the structure of components.The wm class stands for "window manager" that is a mixin class that provides many builtin functions and methods.The method wm_title() is used to change the title of the tkinter window. However, alternatively, we can also use the win.title() method. Generally, wm class provides many methods that let us communicate with the window services.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win = Tk() ...

Read More

How to make a system tray application in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 19-Jun-2021 6K+ Views

A System Tray application is created for the continuous execution of the program. Whenever an application is closed by the user, it will get its state running on the taskbar. To identify a system tray application, we can provide an image or icon to its application.To create a System Tray icon of a tkinter application, we can use pystray module in Python. It has many inbuilt functions and methods that can be used to configure the system tray icon of the application.To install pystray in your machine, you can type "pip install pystray" command in your shell or command prompt.To ...

Read More

Undo and redo features in a Tkinter Text widget

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 19-Jun-2021 2K+ Views

Tkinter Text widget is another input widget similar to the Entry widget which accepts multiline user input in a text field. It contains many inbuilt features and functions which helps to configure the default properties of the text widget. However, to add undo/Redo features in the Tkinter text widget, we can use Boolean attributes undo which ensures that the text can be retrieved again.Example# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x350") # Create a ...

Read More

How to set the position of a Tkinter window without setting the dimensions?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 19-Jun-2021 2K+ Views

Tkinter windows are executed after initializing the object of the Tkinter frame or window. We can define the size of the Tkinter window or frame using the Geometry manager. It defines the width and height of the initial Tkinter window where we generally place our widgets. To set the position of the Tkinter window while omitting the width and height, we can define the specification in the geometry manager.Example# Import the required Libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win = Tk() # Set the geometry of tkinter frame ...

Read More

How to get the absolute path of a file using tkFileDialog(Tkinter)?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 18-Jun-2021 11K+ Views

Tkinter is a standard Python library that is used to create and develop functional and featured applications. It has a variety of inbuilt functions, modules, and packages that can be used for constructing the logic of the application.The tkFileDialog is an inbuilt module available in the Tkinter library which is useful for interacting with the system files and directories. However, once we select a particular file in the read mode using tkFileDialog, potentially it can be used further to process the information available in the file.If you want to access the absolute path of the file when it gets loaded in ...

Read More

How to change ttk.Treeview column width and weight in Python 3.3?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 18-Jun-2021 16K+ Views

To display a large set of data in a Tkinter application, we can use the Treeview widget. Generally, we represent data through tables that contain a set of rows and columns. We can add the data in the form of a table with the help of the Treeview widget.To configure the column width of the Treeview widget, we can use the width and stretch property. It sets the width of the Treeview widget column with the given value.ExampleIn this example, we have created a table that contains a list of programming languages. The width of columns ‘ID’ and ‘Programming Language’ is set ...

Read More

How to fit Tkinter listbox to contents?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 18-Jun-2021 3K+ Views

Tkinter offers Listbox widgets which is very useful in the case of representing a large set of data items in the form of a list. To configure the listbox widget, we can use configure(*options) method to change the properties such as background color, foreground color, and other properties of the listbox widget. The width property is used to define the width of the listbox widget. If we set width=0, then it will get closed to the length of its content in the listbox.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window ...

Read More
Showing 71–80 of 414 articles
« Prev 1 6 7 8 9 10 42 Next »
Advertisements