Found 604 Articles for Tkinter

How to remove the title bar in a Tkinter window without using overrideredirect() method?

Dev Prakash Sharma
Updated on 25-May-2021 08:51:14

7K+ Views

To remove the title bar of a Tkinter window, we can use wm_attributes('type', 'value') method by specifying the type of property. In the following example, we will use 'fullscreen', a Boolean value that removes the title bar of the window.Example#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() win.geometry("700x350") #Create a Label to print the Name label= Label(win, text="This is a New Line Text", font= ('Helvetica 14 bold'), foreground= "red3") label.pack() win.wm_attributes('-fullscreen', 'True') win.mainloop()OutputRunning the above code will display a fullscreen window without the title bar.Read More

What's the difference between Tkinter's Tk and Toplevel classes?

Dev Prakash Sharma
Updated on 25-May-2021 08:50:56

939 Views

Tkinter windows are created by initializing the Tk object first. It is the minimal part of any Tkinter application, which helps to instantiate the application. Tk helps to construct the basic building blocks of the application, such as an application window where all the widgets are placed.However,  Toplevel classes help to communicate through the internal widgets of the main application. One of the examples of toplevel classes is the Toplevel window that displays a child window other than the main window of the application. The Toplevel window works the same as the Tk, as it also can contain widgets and functionalities.Example#Import the required ... Read More

Default window color Tkinter and hex color codes in Tkinter

Dev Prakash Sharma
Updated on 25-May-2021 08:50:36

1K+ Views

A Tkinter window can be customized by adding the properties and attributes such as background color, foreground color, width, height, etc.The color attribute in config() defines the default color of the main window. We can set the color of the window by defining either Hex Color (e.g., #000 for Black) or the Name of the color. The supported Tkinter color chart can be found hereExample# Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x350") #Set the default color of the window win.config(bg = '#24f3f0') # ... Read More

How to compile a Python 3 app to an .exe using Tkinter?

Dev Prakash Sharma
Updated on 25-May-2021 08:50:13

3K+ Views

Python is well-known for its rich library of extensions and packages. We can import and install the necessary packages from the library. However, if we require to run a Tkinter application with an executable file in Windows Operating System, then we can use the Pyinstaller package in Python. It converts a Python-based application to a native executable file (or.exe).Follow the steps to compile a Tkinter-based application into an executable file, Install Pyinstaller using 'pip install pyinstaller'.Open the Command or Shell in the same directory where the application file is located and run the file using the command, pyinstaller --onefile app.py. It ... Read More

Tkinter dropdown Menu with keyboard shortcuts

Dev Prakash Sharma
Updated on 25-May-2021 08:49:46

926 Views

A Dropdown Menu is nothing but a list of vertically stacked menu items that can be visible at the top Menu Bar of an application. We can create a Menu bar in a Tkinter application by creating an object of Menu() in which all the Menu items are present.There might be a case when we want to select the menu and perform some basic operations using Keyboard shortcuts. In order to bind the key to all the Menu, we use the bind_all(, callback) method.ExampleIn this example, the application window contains a Menu of items. When we press the combination of , it ... Read More

How to bind events to Tkinter Canvas items?

Dev Prakash Sharma
Updated on 25-May-2021 08:49:19

2K+ Views

Tkinter events can be bound with the widgets to perform a set of operations on the widgets. To be more specific, we can also bind an event handler to Canvas Items by using bind(, callback) method. Binding the event with the canvas item makes a canvas item dynamic which can be customized by event handlers.Example#Import the required Libraries from tkinter import * import random #Create an instance of Tkinter frame win = Tk() #Set the geometry of the window win.geometry("700x350") #Crate a canvas canvas=Canvas(win, width=700, height=350, bg='white') def draw_shapes(e):    canvas.delete(ALL) canvas.create_oval(random.randint(5, 300), random.randint(1, 300), 25, 25, ... Read More

How to specify where a Tkinter window should open?

Dev Prakash Sharma
Updated on 25-May-2021 08:47:17

7K+ Views

Tkinter window can be configured using the Geometry Manager. When we specify the main window using the geometry(width x height + position_right + position_left) method, then we generally enable the window to open in a particular position.Example#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x350+300+300") #Create a Label Label(win, text="This Window Opens at (300,300)", font=('Helvetica 15 bold')).pack(pady=30) win.mainloop()OutputRunning the above code will display a window at the specified position with a label text.

What is the difference between a variable and StringVar() of Tkinter?

Dev Prakash Sharma
Updated on 04-May-2021 14:17:08

703 Views

A variable in Tkinter is used to store the values of any data. For a Tkinter application, we can store the values in two ways −by defining the value programmatically, orby storing the value through user Input.A normal variable can be used to set the value for any application whenever it is required. However, we can take the user input by creating an instance of the StringVar() object. When we specify a Tkinter variable such as textvariable, for a widget (textvariable = myvar), the widget automatically gets updated whenever the value of the variable changes. However, there might be times ... Read More

How to control automated window resizing in Tkinter?

Dev Prakash Sharma
Updated on 04-May-2021 14:17:33

4K+ Views

The Tkinter window can be resized manually by defining the geometry ("width × height") method. We can automate or reset the window to its original form by passing an empty value to the geometry manager. Once the empty value is passed to the method, it will get resized automatically. In this example, we will create a Tkinter application that will display a Toplevel window (Popup window) with a defined size. When we press a RESET button, it will be resized again to its default size.Example#Import the library from tkinter import * from tkinter import ttk #Create an instance of ... Read More

Tkinter button commands with lambda in Python

Dev Prakash Sharma
Updated on 03-May-2021 11:50:48

25K+ Views

Lamda Functions (also referred to as Anonymous Function in Python) are very useful in building Tkinter GUI applications. They allow us to send multiple data through the callback function. Lambda can be inside any function that works as an anonymous function for expressions. In Button Command, lambda is used to pass the data to a callback function.ExampleIn this example, we will create an application that will have some buttons in it. The button command is defined with the lambda function to pass the specific value to a callback function.#Import the library from tkinter import * from tkinter import ttk ... Read More

Advertisements