Found 310 Articles for GUI-Programming

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

19K+ 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

660 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

25K+ 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

How to set a default string value on a Tkinter Spinbox?

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 13:48:55

2K+ Views

To set a default string value on a Tkinter Spinbox, we will have to use the set method. Let us take an example and see how to create a spinbox with a set of string values and then set a default string.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 strings and save it in a variable, data.Next, use the StringVar() constructor to create a StringVar object. It helps to manage the value of a widget, which is Spingbox in this case. If you don't pass ... Read More

How to draw a line following mouse coordinates with tkinter?

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 13:46:39

2K+ Views

To draw a line following mouse coordinates, we need to create a function to capture the coordinates of each mouse-click and then draw a line between two consecutive points. Let's take an example and see how it can be done.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 "draw_line" to capture the x and y coordinates of each mouse click. Then, use the create_line() method of Canvas to draw a line between two consecutive points.Bind the left-click of the mouse with the draw_line method.Finally, run the ... Read More

How to place the text at the center of an Entry box in Tkinter?

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 13:44:13

8K+ Views

To put a border around a Frame in Tkinter, we have to use the highlightbackground and highlightthickeness parameters while creating the Frame. Let's take an example and see how to use these two parameters.Steps −Import the tkinter library and create an instance of tkinter frame.Set the size of the frame using geometry method.Create a frame with Frame() method. Highlight the border of the frame with a color, highlightbackground="blue". Then, set the thickness of the border, highlightthickness=2.Next, create some widgets inside the frame. In the example, we have placed four checkbuttons and a button inside the frame.Finally, run the mainloop of ... Read More

Previous 1 ... 4 5 6 7 8 ... 31 Next
Advertisements