Create a Timer Using Tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 14:28:45

10K+ Views

In this example, we will create a timer using Python Tkinter. For displaying time, we will use the Time Module in Python.Initially, we will follow these steps to create the timer, Create three entry widget each for Hours, Minute and Seconds and set the value ‘00’ by default.Create a Button for setting the timer. It will call the function countdowntimer().Define a function countdowntimer() which does update once we click on the button to propagate the time.Example#Import the required library from tkinter import * import time #Create an instance of tkinter frame win = Tk() win.geometry('750x300') win.resizable(False, False) #Configure the background ... Read More

Change Tkinter Frame Title

Dev Prakash Sharma
Updated on 15-Apr-2021 14:20:31

4K+ Views

Tkinter window is the native component of tkinter application that contains some frames, a group of widgets, and some other elements. A Tkinter frame has a group of too many widgets.Let us suppose that we have created a frame with some widgets and now we want to rename the title of the application. Frame titles are a necessary part of any application. We can change the title of the frame using the title("title") method.ExampleIn this example, we will create an application that will contain an entry widget and a button. The button is used to rename the title of the ... Read More

Change Font and Size of Buttons and Frame in Tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 14:19:10

7K+ Views

Tkinter Button Widgets are a general way to provide Event Handling in a variety of applications. Sometimes, we may need to style the buttons which are defined in an application. In order to add styling in the button widgets, first create an instance of Button widget using a variable. Then, add some property like fontfamily, font-size, padding, etc. into it. The most general way to resize the button is by resizing the text in it.ExampleIn this example, we have created a button that can be resized by changing the value in the 'font' property.#Import tkinter library from tkinter import * ... Read More

Change Color of TTK Button in Tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 14:08:57

6K+ Views

Tkinter widgets have a consistent look and style across all the platforms and operating systems. Ttk works like CSS in an HTML script. It has many inbuilt functions, modules and methods that add style to a regular tkinter widget. Tkinter ttk buttons generally have a default color scheme, thus we can change the background color of these buttons by configuration method.ExampleIn this example, we will create a button which when pressed will change its style.#Import the necessary library import itertools from tkinter import * from tkinter import ttk #Create an instance of tkinter window win = Tk() #Set the geometry ... Read More

Change Text Cursor Color in Tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 14:07:01

2K+ Views

Tkinter Entry and text widgets are used to create single and multiline text input fields. In order to change the color of the cursor, we can specify the insertbackground property by assigning the color of the cursor.ExampleIn this example, we have created the text field and we have changed the color of the cursor by defining the insertbackground property.#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win= Tk() win.geometry("750x250") #Create a text field text= Text(win) text.configure(bg= 'SteelBlue3', insertbackground='red') text.pack() win.mainloop()OutputNow, write something in the text field to see the reflected color of the cursor.Read More

Bind Click Event to Canvas in Tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 14:04:40

3K+ Views

The Canvas widget is undoubtedly the most powerful widget available in tkinter. It can be used to create and develop from custom widgets to a complete user interface. We can even bind the click event to handle the canvas and its object.ExampleIn this example, we will add an image inside the canvas widget and will bind a button object to remove the image from the canvas.In order to bind a click event, we can use the tag_bind() method and use the delete(image object) to delete the image.#Import the required library from tkinter import* #Create an instance of tkinter frame win= ... Read More

Add Space Between Two Widgets in a Grid in Tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 13:59:13

10K+ Views

Let us assume that we are creating a tkinter application where two or more widgets are placed using a grid property. We have to add some space between the widgets in order to style their appearance. To provide space in the widgets, we can use padding property, as padding adds space to the outermost part of the widget. In order to add padding, assign the values to padx and pady.Example#Import the required library from tkinter import * #create an instance of tkinter frame win= Tk() win.geometry("750x250") #Create some Button widgets Label(win, text= "New Line Text", font= ('Helvetica 20 bold')).grid(row=0, column=5, ... Read More

Give Focus to a Python Tkinter Text Widget

Dev Prakash Sharma
Updated on 15-Apr-2021 13:51:44

3K+ Views

In various applications, tkinter widgets are required to be focused to make them active. Widgets can also grab focus and prevent the other events outside the bounds. To manage and give focus to a particular widget, we generally use the focus_set() method. It focuses the widget and makes them active until the termination of the program.ExampleIn the following example, we have created two widgets: an Entry widget and a text widget in the same window. By using the focus_set() method, we will activate the focus on the text widget.#Import tkinter library from tkinter import * from PIL import Image, ImageTk ... Read More

Copy All Elements of One Array into Another Array in Python

AmitDiwan
Updated on 15-Apr-2021 13:48:39

1K+ Views

When it is required to copy all the elements from one array to another, an empty array with ‘None’ elements is created. A simple for loop is used to iterate over the elements, and the ‘=’ operator is used to assign values to the new list.Below is a demonstration of the same −Example Live Demomy_list_1 = [34, 56, 78, 90, 11, 23] my_list_2 = [None] * len(my_list_1) for i in range(0, len(my_list_1)):    my_list_2[i] = my_list_1[i] print("The list is : ") for i in range(0, len(my_list_1)): print(my_list_1[i]) print() print("The new list : ") for i in ... Read More

Construct a Tree and Perform Insertion, Deletion, Display in Python

AmitDiwan
Updated on 15-Apr-2021 13:47:54

649 Views

When it is required to construct a binary tree, and perform operations such as inserting an element, deleting an element and displaying elements of the tree, a class is defined with methods in it. An instance of the class is defined and this is used to access the elements and perform operations.Below is a demonstration of the same −Example Live Democlass Tree_struct:    def __init__(self, data=None, parent=None):       self.key = data       self.children = []       self.parent = parent    def set_root(self, data):       self.key = data    def add_node(self, node): ... Read More

Advertisements