Found 604 Articles for Tkinter

Creating a LabelFrame inside a Tkinter Canvas

Dev Prakash Sharma
Updated on 16-Dec-2021 10:54:10

1K+ Views

Tkinter provides many built-in widgets which can be used to create highlevel desktop applications. The LabelFrame widget is one of them, which allows the users to add a labelled frame. The Label is another widget in the LabelFrame, which is used to add text or images in a frame or any container.There are two main components of the LabelFrame widget, The Title Bar (also known as the text of the LabelFrame widget).The content (the content of the LabelFrame widget. You can add an image, or text as the content inside the LabelFrame widget.)To define a LabelFrame widget, you’ll need to ... Read More

How to get a new API response in a Tkinter textbox?

Dev Prakash Sharma
Updated on 16-Dec-2021 10:52:25

915 Views

APIs are extremely useful in implementing a service or feature in an application. APIs help to establish the connection between the server and a client, so whenever a client sends a request using one of the API methods to the server, the server responds with a status code (201 as a successful response) to the client.You can make a request to any API you want using one of the methods (GET, POST, PUT or DELETE). However, if you want to create an application where you need a request to the server using one of the publicly available API (for example, ... Read More

Adding coloured text to selected text in Tkinter

Dev Prakash Sharma
Updated on 16-Dec-2021 10:42:46

1K+ Views

If we want to implement a text editor in an application that can accept multiline user input, then we can use the Tkinter Text widget. The Text widget in Tkinter is generally used to create a text editor for an application, where we can write text and perform operations like selecting, editing and creating a specific text in the application.If you want to highlight a text and provide a color to the highlighted text, then you can use the tag_add("start", "first", "second") method. The tag_add() method takes two arguments for selecting the specified text from the text widget. You can ... Read More

How to set a certain number of rows and columns of a Tkinter grid?

Dev Prakash Sharma
Updated on 16-Dec-2021 10:41:34

3K+ Views

In Tkinter, you can set the GUI of the application by using a different geometry manager. The grid geometry manager is one of the most useful geometry managers in tkinter that is used to set the widgets location in the application using the 2D geometry form.With a grid geometry manager, you can set a certain number of rows and columns and place the widget in any location of the application. To set a certain number of rows and columns, you’ll need to specify the size value of the row and column configuration that helps to set the location of a ... Read More

How to insert a temporary text in a tkinter Entry widget?

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 14:43:03

20K+ Views

To insert a temporary text in a tkinter Entry widget, we will bind the event with the Entry widget and call a user-defined function to delete the text inside the Entry widget.Steps −Import the tkinter library and create an instance of tkinter frame.Set the size of the frame using geometry method.Create a user-defined method "temp_text()" to capture the event and delete the temporary text inside the Entry widget.Create an Entry widget inside the Root window and set its properties such as background color, width, and border width.Use the insert() method of the Entry widget to insert a string ... Read More

How to update a Button widget in Tkinter?

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 14:39:35

2K+ Views

We can update a Button widget in Tkinter in various ways, for example, we can change its size, change its background color, or remove its border, etc. In the following example, we will create three Button widgets and each of the buttons, upon clicking, will call a different function to update their features.Example# Import the required library from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win = Tk() # Define geometry of the window win.geometry("700x300") # Function to Increase the Size of the Button def Button_Size(): button1.configure(font=('Calibri ... Read More

How to show the status of CAPS Lock Key in tkinter?

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 14:32:34

728 Views

We can use the and bindings to check if the CAPS Lock Key is ON or off. In the following example, we will create two user-defined functions "caps_lock_on()" and "caps_lock_off()" which will capture the event of Lock-KeyPress and Lock-KeyRelease and print the status on the screen.Example# Import required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win = Tk() # Define the geometry of the window win.geometry("700x250") win.title("CAPS Lock Status") def caps_lock_on(e): label_caps.config(text="CAPS Lock is ON") def caps_lock_off(e): label_caps.config(text="CAPS ... Read More

How to call a function using the OptionMenu widget in Tkinter?

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 14:28:55

4K+ Views

Let's take an example and see how to call a function using OptionMenu widget in Tkinter. In the example, we will use a StringVar object and call its get() method. A StringVar object in Tkinter can help manage the value of a widget.We will create an OptionMenu widget and fill it with a list of strings. When the user selects an option, it will invoke a function which in turn will print the selected option as a label.Steps −Import the tkinter library and create an instance of tkinter frame.Set the size of the frame using geometry method.Create a set of ... Read More

How to get the longitude and latitude of a city using Python?

Kiran Kumar Panigrahi
Updated on 29-Aug-2023 03:28:47

28K+ Views

To get the longitude and latitude of a city, we will use the geopy module. geopy uses third-party geocoders and other data sources to locate the coordinates of addresses, cities, countries, etc.First of all, make sure the geopy module is installed −pip install geopyIn the following example, we will use the Nominatim geocoder to find the longitude and latitude of the city "Hyderabad".Steps −Import Nominatim geocoder from geopy module.Initialize the Nominatim API and use the geocode method to get the location of the input string.Finally, get the latitude and longitude of the location by location.latitude and location.longitude.Example 1# Import the ... Read More

How to use a StringVar object in an Entry widget in Tkinter?

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 13:51:25

4K+ Views

A StringVar object in Tkinter can help manage the value of a widget such as an Entry widget or a Label widget. You can assign a StringVar object to the textvariable of a widget. For example, data = ['Car', 'Bus', 'Truck', 'Bike', 'Airplane'] var = StringVar(win) my_spinbox = Spinbox(win, values=data, textvariable=var)Here, we created a list of strings followed by a StringVar object "var". Next, we assigned var to the textvariable of a Spinbox widget. To get the current value of the Spinbox, you can use var.get().ExampleThe following example demonstrates how you can use a StringVar object in an ... Read More

Advertisements