Python Articles

Page 746 of 855

How do I set a minimum window size in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 27-Mar-2021 3K+ Views

A Tkinter window can be initialized after running the application. Generally, the width and the height of the window is resizable which can be minimized.In order to set the window size to its minimum value, assign the value of width and height in minsize(height, width) method. The method can be invoked with the window or frame object.Example#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Minimize the window win.minsize(150, 100) #Create a text label Label(win, text= "Window Size is minimized to 150x100", font=('Helvetica bold', 20)).pack(pady=20) win.mainloop()OutputRunning the above code ...

Read More

How to bundle a Python Tkinter application including dependencies?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 26-Mar-2021 993 Views

Let us suppose we have created a tkinter application and now, we want to bundle the standalone application to make it portable and executable. We can use different Python packages that support various functionality to bundle the whole application code into an executable installer. These packages compress the code and convert the standalone application into an executable code.For a Windows-based user, we can use py2exe; for Linux, we can use Freeze; and for Mac, we can use py2app.ExampleIn this example, we have created a Windows-based application that prints “Hello World” on the screen. Initially, we will create a setup.py file ...

Read More

How to center a window on the screen in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 26-Mar-2021 22K+ Views

In order to place a tkinter window at the center of the screen, we can use the PlaceWindow method in which we can pass the toplevel window as an argument and add it into the center.We can also set the window to its center programmatically by defining its geometry.Example#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("600x250") win.eval('tk::PlaceWindow . center') win.mainloop()OutputRunning the above code will create a centered window.

Read More

How to change the color of certain words in a Tkinter text widget?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 26-Mar-2021 11K+ Views

Tkinter text widgets are used to create and display multiline text Input. It provides several functions and methods that are generally used to configure a text widget.Let us suppose we want to change the color of certain words in a text widget, then we can use the tag_add(tag name, range) method which selects the word we want to format. Once the word has been selected, we can change its color, background color, and other properties using the tag_config(properties) method.ExampleIn this example, we will configure the color of a selected word in the text widget.#Import required libraries from tkinter import * ...

Read More

How to clear an entire Treeview with Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 26-Mar-2021 7K+ Views

Tkinter Treeview widgets are used to display the hierarchy of the items in the form of a list. It generally looks like the file explorer in Windows or Mac OS.Let us suppose we have created a list of items using treeview widget and we want to clear the entire treeview, then we can use the delete() function. The function can be invoked while iterating over the treeview items.ExampleIn this example, we will create a treeview for the Programming Language and will clear the list of items using delete() operation.#Import the required library from tkinter import * from tkinter import ttk ...

Read More

How to clear out a frame in the Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 26-Mar-2021 25K+ Views

Tkinter frames are used to group and organize too many widgets in an aesthetic way. A frame component can contain Button widgets, Entry Widgets, Labels, ScrollBars, and other widgets.If we want to clear the frame content or delete all the widgets inside the frame, we can use the destroy() method. This method can be invoked by targeting the children of the frame using winfo_children().Example#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("600x250") #Create a frame frame = Frame(win) frame.pack(side="top", expand=True, fill="both") #Create a ...

Read More

How to clear the contents of a Tkinter Text widget?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 26-Mar-2021 24K+ Views

Tkinter Text Widget is used to add the text writer in an application. It has many attributes and properties which are used to extend the functionality of a text editor. In order to delete the input content, we can use the delete("start", "end") method.Example#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("600x250") #Define a function to clear the input text def clearToTextInput():    my_text.delete("1.0", "end") #Create a text widget my_text=Text(win, height=10) my_text.pack() #Create a Button btn=Button(win, height=1, width=10, text="Clear", command=clearToTextInput) btn.pack() #Display ...

Read More

How to clear Tkinter Canvas?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 26-Mar-2021 26K+ Views

Tkinter provides a way to add a canvas in a window and when we create a canvas, it wraps up some storage inside the memory. While creating a canvas in tkinter, it will effectively eat some memory which needs to be cleared or deleted.In order to clear a canvas, we can use the delete() method. By specifying “all”, we can delete and clear all the canvas that are present in a tkinter frame.Example#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("650x250") #Creating a canvas myCanvas =Canvas(win, ...

Read More

How to create a download progress bar in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 26-Mar-2021 2K+ Views

Let’s suppose that we are creating an application which interacts with sources and files such as downloading the files, tracking the file. In order to make a progressbar for such an application, we will use the tkinter.ttk package that includes the Progressbar module.Initially, we will instantiate an object of Progressbar which has orientation of Horizontal. Then, we will define a function to increase the value of the progressbar and keep updating it.ExampleIn the following example, we have created a download progress bar by updating its value.#Import the required libraries from tkinter import * from tkinter.ttk import * import time ...

Read More

How to create a multiline entry with Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 26-Mar-2021 2K+ Views

Let us suppose that we want to create an Entry widget that supports multiline user input. In order to create a multiline Entry widget, we can use Text() constructor.ExampleHere, in this example, we will create a window that contains a multiline Entry widget.#Import the library from tkinter import * #Create an object of tkinter window or frame win = Tk() #Define the geometry of window win.geometry("650x250") #Create an instance of Text Widget text = Text(win) text.pack() win.mainloop()OutputRunning the above code will display a window with a text widget that supports multiline user Input.

Read More
Showing 7451–7460 of 8,547 articles
« Prev 1 744 745 746 747 748 855 Next »
Advertisements