Found 605 Articles for Tkinter

How to delete Tkinter widgets from a window?

Dev Prakash Sharma
Updated on 26-Mar-2021 10:54:36

6K+ Views

Sometimes, we want to remove a widget that is of no use in the application. We can delete widgets from the window or frame using the .destroy method in tkinter. It can be invoked in the widget by defining a function for it.ExampleIn this example, we have created a button that will remove the text label widget from the window.#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("650x450") #Define a function to remove the text from the screen def delete_text():    text.destroy() #Create a ... Read More

How to display full-screen mode on Tkinter?

Dev Prakash Sharma
Updated on 26-Mar-2021 10:51:08

11K+ Views

Tkinter displays the application window by its default size. However, we can display a full-screen window by using attributes('fullscreen', True) method. The method is generally used for assigning a tkinter window with properties like transparentcolor,  alpha, disabled, fullscreen, toolwindow, and topmost.Example#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("650x250") #Add a text label and add the font property to it label= Label(win, text= "Hello World!", font=('Times New Roman bold', 20)) label.pack(padx=10, pady=10) #Create a fullscreen window win.attributes('-fullscreen', True) win.mainloop()OutputRunning the above code will ... Read More

How to get the input from the Tkinter Text Widget?

Dev Prakash Sharma
Updated on 13-Jul-2021 08:01:56

8K+ Views

In tkinter, we can create text widgets using Text attributes using packages. However, while creating a GUI application, sometimes we need to capture the input from a text widget.We can get the input from the user in a text widget using the .get() method. We need to specify the input range which will be initially from 1.0 to END that shows the characters starting and ending till the END.Example#Import tkinter library from tkinter import * #Create an instance of tkinter window or frame win=Tk() win.geometry("700x300") def get_input():    value=my_text_box.get("1.0", "end-1c")    print(value) #Creating a text box widget ... Read More

How to get the screen size in Tkinter?

Dev Prakash Sharma
Updated on 26-Mar-2021 10:48:33

16K+ Views

Tkinter initially creates a window or frame object where all the widgets, frame are displayed.Tkinter components adjust the window size and width according to user-defined geometry.In order to get the screen size, we can use winfo_screenwidth() which returns the screen width and winfo_screenheight() for the height of the screen in pixels.ExampleIn this example, we will print the screen size as the output, #Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("650x250") #Get the current screen width and height screen_width = win.winfo_screenwidth() screen_height = win.winfo_screenheight() ... Read More

How to get the Tkinter Label text?

Dev Prakash Sharma
Updated on 26-Mar-2021 10:48:08

1K+ Views

Tkinter Labels are used to create and display text or images on the window. It has several components and functions that can be used to customize the label information such as fontfamily, padding, width, height, etc. In order to get the Label text on the window, we can write the value for the text that has to be displayed on the window.Example#Import the required library from tkinter import * #Create an instance of tkinter frame win= Tk() #Define the geometry of the window win.geometry("600x250") #Create a Label with Text my_text= Label(win, text= "This is a New Line ... Read More

How to install Tkinter for Python on Linux?

Dev Prakash Sharma
Updated on 26-Mar-2021 10:46:32

13K+ Views

Tkinter is one of the widely used libraries for creating GUI-based applications. In order to create applications using Tkinter, we have to install and import the library in the notebook.First, we have to install the tkinter library in our local environment based on the Windows or Linux operating system.For Windows users −pip install tkinterorpip install tkFor Linux or Mac users −apt-get install python-tkOnce installed, the user can import the tkinter library in the notebook using the following command, from tkinter import* To check if tkinter is installed in the system or not, we can use the following command, import tkinter ... Read More

How to make a Tkinter widget invisible?

Dev Prakash Sharma
Updated on 26-Mar-2021 10:42:38

4K+ Views

To make a tkinter widget invisible, we can use the pack_forget() method. It is generally used to unmap the widgets from the window.ExampleIn the following example, we will create a label text and a button that can be used to trigger the invisible event on the label text widget.#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("600x250") #Set the resizable property False win.resizable(False, False) #Make the widgets Invisible def make_invisible(widget):    widget.pack_forget() #Create a label for the window or frame label=Label(win, text="Hello ... Read More

How to make a Tkinter window jump to the front?

Dev Prakash Sharma
Updated on 26-Mar-2021 10:40:50

2K+ Views

In order to make the tkinter window or the root window jump above all the other windows, we can use attributes method that will generally take two values specifying the “topmost” value and the other is a Boolean value.Example#Importing the library from tkinter import * #Create an instance of tkinter window or frame win= Tk() #Setting the geometry of window win.geometry("600x250") #Create a Label Label(win, text= "Hello Everyone!", font=('Helvetica bold', 15)).pack(pady=20) #Make the window jump above all win.attributes('-topmost', 1) win.mainloop()OutputRunning the above code will make the window stay above all other windows,Read More

How to make a Tkinter window not resizable?

Dev Prakash Sharma
Updated on 26-Mar-2021 10:39:51

7K+ Views

Tkinter initially creates a resizable window for every application. Let us suppose that we want to make a non-resizable window in an application. In this case, we can use resizable(height, width) and pass the value of height=None and width=None. The method also works by passing Boolean values as resizable(False, False).Example#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("600x250") #Set the resizable property False win.resizable(False, False) #Create a label for the window or frame Label(win, text="Hello World!", font=('Helvetica bold', 20), anchor="center").pack(pady=20) win.mainloop()OutputRunning the above code will ... Read More

How to put a Tkinter window on top of the others?

Dev Prakash Sharma
Updated on 26-Mar-2021 10:37:05

8K+ Views

Whenever we create a GUI program, tkinter generally presents the output screen in the background. In other words, tkinter displays the program window behind other programs. In order to put the tkinter window on top of others, we are required to use attributes('- topmost', True) property. It pulls up the window on the upside.Example#Importing the library from tkinter import * #Create an instance of tkinter window or frame win= Tk() #Setting the geometry of window win.geometry("600x350") #Create a Label Label(win, text= "Hello World! ", font=('Helvetica bold', 15)).pack(pady=20) #Make the window jump above all win.attributes('-topmost', True) ... Read More

Advertisements