Found 605 Articles for Tkinter

Adding a scrollbar to a group of widgets in Tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 13:08:31

549 Views

Let’s suppose you want to add a scrollbar to a group of widgets in an application, then you can use the Scrollbars property in tkinter. Adding Scrollbars to a group of widgets can be achieved by Scrollbar(....options).ExampleIn this example, we will define a group of Listbox widgets and then add a vertical scrollbar to make the list scrollable.#Import the required library from tkinter import * #Create an instance of tkinter frame or window win = Tk() #Define the geometry win.geometry("750x400") #Create a listbox listbox= Listbox(win) listbox.pack(side =LEFT, fill = BOTH) #Create a Scrollbar scrollbar = Scrollbar(win) ... Read More

Add advanced features to a tkinter Text widget

Dev Prakash Sharma
Updated on 15-Apr-2021 13:06:12

458 Views

Tkinter text widget is much more than just a multiline text editor. It is useful for many applications where user interaction is required.In order to configure the text widget, tkinter provides many functions and methods. Some of the features that we can add to style the text widgets are: changing the font-family, background-color, foreground-color, adding and selecting a particular text, changing font-size, and many more.ExampleIn this example, we will see how we can add different features to a particular text widget, #Import tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set ... Read More

Difference between tkinter and Tkinter

Dev Prakash Sharma
Updated on 27-Mar-2021 06:30:05

979 Views

In order to install tkinter in a local computer, we use several commands on the basis of our OS architecture. There are two ways to import the tkinter library in our Window-based machine which are based on the Python version. Earlier, for lower versions of Python, we generally used to import the tkinter library using the following command −from Tkinter import *However, for Python 3 or later, we generally import the Tkinter library in the environment using the following command −from tkinter import *The only difference between Tkinter and tkinter is that Tkinter was initially used with Python 2 and ... Read More

Display message when hovering over something with mouse cursor in Tkinter Python

Dev Prakash Sharma
Updated on 27-Mar-2021 06:29:42

4K+ Views

Let us suppose we want to create an application where we want to add some description on tkinter widgets such that it displays tooltip text while hovering on the button widget. It can be achieved by adding a tooltip or popup.Tooltips are useful in applications where User Interaction is required. We can define the tooltip by instantiating the constructor of Balloon(win). After that, we can bind the button with the tooltip message that applies on the widget.Example#Import the tkinter library from tkinter import * from tkinter.tix import * #Create an instance of tkinter frame win = Tk() #Set the ... Read More

Draw a circle in using Tkinter Python

Dev Prakash Sharma
Updated on 27-Mar-2021 06:29:22

12K+ Views

Tkinter Canvas are generally used for creating shapes such as arc, rectangle, triangle, freeform shapes, etc. All these shapes can be drawn using the inbuilt function available in tkinter library.ExampleIn this example, we will create a Circle using the create_oval(x0, y0, x1, y1) method by passing the following values of coordinates (x0, y0, x1, y1)#Import the library from tkinter import * #Create an instance of tkinter frame win= Tk() #Define the geometry of window win.geometry("600x400") #Create a canvas object c= Canvas(win, width=400, height=400) c.pack() #Draw an Oval in the canvas c.create_oval(60, 60, 210, 210) win.mainloop()OutputRunning ... Read More

Function to close the window in Tkinter

Dev Prakash Sharma
Updated on 27-Mar-2021 06:27:03

1K+ Views

Whenever we run a tkinter application, it displays a GUI-based window that would have widgets, frames, and other elements. Let us suppose we want to close our application with a function. The destroy() method in Python tkinter is used to terminate the normal execution of the application after the mainloop function.ExampleIn this example, will create a button object which triggers to close the application.#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("650x250") #Define a function def close_app():    win.destroy() #Create a text Label Label(win, text= ... Read More

How can I create a dropdown menu from a List in Tkinter?

Dev Prakash Sharma
Updated on 22-Apr-2021 06:09:57

13K+ Views

Let us suppose we want to create a dropdown menu of a list in an application using tkinter. In this case, we can use the Tkinter OptionMenu(win, menu_to_set, options) function.First, we will instantiate an object of StringVar(), then we will set the initial value of the dropdown menu. We will create the dropdown menu by creating an object of OptionMenu and passing the value of window, menu object, and options which are to be displayed.Example#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Define the size of window or frame win.geometry("715x250") ... Read More

How can I prevent a window from being resized with Tkinter?

Dev Prakash Sharma
Updated on 27-Mar-2021 06:21:20

12K+ Views

Tkinter windows can be resized automatically by hovering and pulling over the window. We can disable the resizable property using the resizable(boolean value) method. We will pass false value to this method which will disable the window to be resized.Example#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("650x250") Label(win, text= "Hello World", font=('Times New Roman bold', 20)).pack(pady=20) #Make the window resizable false win.resizable(False, False) win.mainloop()OutputRunning the above code will display the following the tkinter window, but you won't be able to resize it.Read More

How do I bind the enter key to a function in Tkinter?

Dev Prakash Sharma
Updated on 27-Mar-2021 06:20:58

6K+ Views

Pressing a key and handling some operation with the key is an event that can be triggered through a button. We can bind the key event using the Binding method in a tkinter application.Whenever the key will be triggered, it will call a handler that will raise the specific operation for the key event.If we want to trigger the Enter key with the bind function, we will use the bind('', Handler) method. For Enter Key, we use bind('', Handler) function.Example#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the ... Read More

How do I change button size in Python Tkinter?

Dev Prakash Sharma
Updated on 26-Aug-2023 08:07:09

37K+ Views

Tkinter Button widgets are used to create buttons that are necessary for an application. We can also add an event Object in the Button constructor and trigger it to perform some operation.In order to customize the Button size, we can use the width and height property of the button widget.ExampleIn this example, we will create some buttons with different sizes, #Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("600x250") win.resizable(False, False) Button(win, text="Button-1", height= 5, width=10).pack() Button(win, text="Button-2", height=8, width=15).pack() Button(win, text= "Button-3", ... Read More

Advertisements