Update Button Widget in Tkinter

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

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

Number of Integral Solutions of the Equation x1 + x2 + ... + xn = k in C++

Hafeezul Kareem
Updated on 26-Oct-2021 14:35:40

400 Views

The solutions for the equation areThe number of non-negative integral solutions of the equation are $\left(\begin{array}{c}n-k+1\ k\end{array}\right)$The number of positive integral solutions of the equation are $\left(\begin{array}{c}k-1\ n-1\end{array}\right)$Add both to get the required answer. Let's see an example.Inputn = 4 k = 7Output140 AlgorithmInitialise the numbers n and k.Find the integral solutions of not-negative and positive numbers.Add both of them.Return the answer.ImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; int factorial(int n) {    int product = 1;    for (int i = 2; i Read More

Show the Status of Caps Lock Key in Tkinter

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

962 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

Call a Function Using OptionMenu Widget in Tkinter

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

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

Use StringVar Object in Entry Widget in Tkinter

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

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

Set Default String Value on a Tkinter Spinbox

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

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

Draw Line Following Mouse Coordinates with Tkinter

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

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

Center Text in Entry Box Using Tkinter

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

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

Copy from Clipboard Using Python and Tkinter

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 13:40:07

7K+ Views

To copy from clipboard, we can use the clipboard_get() method of Tkinter. Let's take an example and see how to get the data from the clipboard and display it on a Tkinter window.Steps −Import the tkinter library and create an instance of tkinter frame.Set the size of the frame using geometry method.Next, call clipboard_get() to get the text from the clipboard and store the data in a variable "cliptext".Create a label to the display the clipboard text. Pass cliptext as text, "text=cliptext".Finally, run the mainloop of the application window.Example# Import the tkinter library from tkinter import * # Instance ... Read More

Number of Integral Points Between Two Points in C++

Hafeezul Kareem
Updated on 26-Oct-2021 13:40:00

586 Views

In this tutorial, we are going to write a program the finds the number of integral points between the given two points.The number of points between two given points will be gcd(abs(x2), abs(y1-y2)) - 1.If the line joining is parallel to x-axis, then the number of integral points will be abs(y1 - y2) - 1.If the line joining is parallel to y-axis, then the number of integral points will be abs(x1 - x2) - 1If the x points of both points are equal, then they are parallel to the x-axis. If the y points of both points are equal, then ... Read More

Advertisements