Found 310 Articles for GUI-Programming

How to highlight the current line of a Text widget in Tkinter?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:31:36

1K+ Views

We can use the Tkinter text widget to accept multiline user input. We can insert text, display information, and get the output from the text widget.To highlight the currently selected text in a text widget, we can use the tag_add() method that adds a tag in the current text only.Example# Import the required library from tkinter import * # Create an instance of tkinter frame win=Tk() # Set the geometry win.geometry("700x350") # Add a text widget text=Text(win, width=80, height=15, font=('Calibri 12')) # Set default text for text widget text.insert(INSERT, "Tkinter is a Python Library to create ... Read More

How do I print and have user input in a text box in Tkinter?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:29:33

8K+ Views

We can use the Tkinter text widget to insert text, display information, and get the output from the text widget. To get the user input in a text widget, we've to use the get() method. Let's take an example to see how it works.Example# Import the required library from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win=Tk() # Set the geometry win.geometry("700x350") def get_input():    label.config(text=""+text.get(1.0, "end-1c")) # Add a text widget text=Text(win, width=80, height=15) text.insert(END, "") text.pack() # Create a button to get the text input b=ttk.Button(win, ... Read More

How to get an element to stick to the bottom-right corner in Tkinter?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:28:14

2K+ Views

Tkinter has many inbuilt features, functions, and methods that we can use to construct the GUI of an application. It is necessary to know how we can set the position of a particular widget in the application so that it becomes responsive in nature.Tkinter also provides geometry managers through which we can set the position of elements and widgets. The Place geometry manager is used for configuring the position of complex widgets.ExampleLet us suppose that we want our widget position to the bottom-right of the application window, then we can use place geometry manager with anchor property.# Import the required ... Read More

How to align text to the right in ttk Treeview widget?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:26:28

2K+ Views

The Treeview widget is used to display the data in a hierarchical structure. Generally, the data is represented through the table that contains 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 position of the item in the column, we can use the anchor property. It sets the position of the Treeview widget column with the given value. Each row in the table is associated with a column. To align the text of the rows towards the right, we can use the anchor ... Read More

How to make Tkinter Window appear in the taskbar?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:25:02

2K+ Views

A System Tray application is always created on the taskbar. 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 the 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 create a ... Read More

How to change the background color of a Treeview in Tkinter?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:22:56

3K+ Views

The Treeview widget is designed to display the data in a hierarchical structure. It can be used to display the directories, child directories or files in the form of a list. The items present in the Listbox are called Listbox items.The treeview widget includes many properties and attributes through which we can change or modify its default properties. We can change the background of a treeview widget by defining the 'background' property in the constructor.Example# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame or window win = Tk() ... Read More

How do I change the Tkinter default title in the OS bar?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:20:43

660 Views

The Tkinter application window has many components: window size, title, navbar, menubar-component, etc. To configure the window attributes or properties, we can use the Window Manager toolkit defined in Tcl/Tk.To run the Window Manager attributes, use the command 'wm' with other keywords. The title of the window can be configured by using wm_title("title") or title("title") method.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") # Change the title of the window win.wm_title("My Window") Label(win, text="Hello, Welcome to Tutorialspoint...", ... Read More

How to clear a Tkinter ListBox?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:19:37

11K+ Views

To create a list of items with a scrollable widget, Tkinter provides the Listbox widget. With the Listbox widget, we can create a list that contains items called List items. Depending upon the configuration, the user can select one or multiple items from the list.If we want to clear the items in the Listbox widget, we can use the delete(0, END) method. Besides deleting all the items in the Listbox, we can delete a single item as well by selecting an item from the Listbox, i.e., by using currselection() method to select an item and delete it using the delete() ... Read More

How to put a Toplevel window in front of the main window in Tkinter?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:17:55

3K+ Views

The Tkinter Toplevel window creates an additional window apart from the main window. We can add widgets and components to the newly created top-level window. It supports all the properties of the parent or main window.Sometimes the Toplevel window is also referred to as the child window. To put the child window in front of the parent window, we can use the wm_transient() method.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") win.title("Parent Window") # ... Read More

How can I set the row height in Tkinter TreeView?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:16:58

7K+ Views

The treeview widget in Tkinter provides a way to represent the data in a hierarchical structure. With the Treeview widget, we can insert our data in the form of a table. The table can have rows and columns in which we can insert the data instantly.We can also configure the properties of the treeview widget such as its color, size, column width, height, row width & height, etc. To set the row height of the Treeview widget, you can create an instance of ttk themed widget where you can specify the rowheight property. The rowheight property will add internal padding ... Read More

Advertisements