Dev Prakash Sharma

Dev Prakash Sharma

414 Articles Published

Articles by Dev Prakash Sharma

Page 35 of 42

How to Update the label of the Tkinter menubar item?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 04-May-2021 1K+ Views

A Menubar contains a set of Menu Item in which each Menu Item is defined for different functionalities or operations. Let us suppose that we want to update the label of Menu Bar Items, then we can use entryconfigure(item_number, options..) method in a callback. To update the Menu Items in the Menu Bar, we can add label in the above method.ExampleLet us create an application with a list of Menu Items in the Menu Bar. When we will click a Particular Item, it will change the text in it.#Import the required Library from tkinter import * #Create an Instance of tkinter frame ...

Read More

Is it possible to color a specific item in a Tkinter Listbox widget?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 04-May-2021 3K+ Views

Tkinter ListBox widget is generally used for creating a list of items in the form of a list. The items can be chosen through the mouse buttons whenever we click a particular List Item. Each item in the ListBox is configured with the default color, which can be changed by defining the ‘background’ and ‘foreground’ color in itemconfig(options) method.ExampleIn this example, we will create a ListBox that contains a list of items. We will provide different colors to a few of the list items.#Import required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Define ...

Read More

How to control automated window resizing in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 04-May-2021 5K+ Views

The Tkinter window can be resized manually by defining the geometry ("width × height") method. We can automate or reset the window to its original form by passing an empty value to the geometry manager. Once the empty value is passed to the method, it will get resized automatically. In this example, we will create a Tkinter application that will display a Toplevel window (Popup window) with a defined size. When we press a RESET button, it will be resized again to its default size.Example#Import the library from tkinter import * from tkinter import ttk #Create an instance of ...

Read More

What is the difference between a variable and StringVar() of Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 04-May-2021 1K+ Views

A variable in Tkinter is used to store the values of any data. For a Tkinter application, we can store the values in two ways −by defining the value programmatically, orby storing the value through user Input.A normal variable can be used to set the value for any application whenever it is required. However, we can take the user input by creating an instance of the StringVar() object. When we specify a Tkinter variable such as textvariable, for a widget (textvariable = myvar), the widget automatically gets updated whenever the value of the variable changes. However, there might be times ...

Read More

Rock Paper and Scissor Game Using Tkinter

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 03-May-2021 3K+ Views

Tkinter is one of the Python-based libraries used to create and develop Desktop User interfaces and applications. Using the Tkinter library and its packages, we will create a Rock Paper Scissor Game Application. The game can be played between two people using hand gestures. The condition for winning the game is, If player A gets Paper and Player B gets scissors, then Scissor wins.If player A gets Paper and Player B gets Rock, then Paper wins.Similarly, If player A gets Rock and Player B gets scissors, then Rock wins.Following these game conditions, we will first create the GUI for the game user interface. The ...

Read More

Placing plot on Tkinter main window in Python

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 03-May-2021 3K+ Views

Oftentimes, we need to deal with plots in our Tkinter GUI-based application. To support the plots for the available data points, Python provides a Matplotlib package that can be imported into the application easily. In order to add a plot for the given data points, we have to install several other packages such as NumPy along with Matplotlib. NumPy is a Python library that helps to deal with scientific calculation in the Data.ExampleIn this example, we will create data points for the car prices starting from (100000) with the units in the range of 1000 to 5000.#Import the required Libraries ...

Read More

How to show a window that was hidden using the "withdraw" method in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 03-May-2021 8K+ Views

Tkinter withdraw method hides the window without destroying it internally. It is similar to the iconify method that turns a window into a small icon. Let us suppose we want to reveal the hidden window during the execution of an application then we can use deiconify() method. It can be invoked with the window or frame of a widget in the application.ExampleIn this example, we will define a button in a Toplevel window (Popup Window) which can be the trigger to reveal the main window.#Import the library from tkinter import * from tkinter import ttk #Create an instance of Tkinter frame win= ...

Read More

How to draw images in the Tkinter window?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 03-May-2021 1K+ Views

To process images with Tkinter and other Python packages, we generally refer to use Pillow Package or PIL in Python. It provides a way to load and process the images in the program wherever we need. Initially, we convert the image to an instance of PhotoImage object that allows images to be further used in many use cases. Further, the Canvas widget in Tkinter helps to draw the images in a Tkinter application, we can use the create_image(x, y, image_file) method to display the image in a particular application.Example#Import the required Libraries from tkinter import * from PIL import Image, ...

Read More

How to stop Tkinter after function?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 03-May-2021 6K+ Views

Tkinter functions can be created with the help of threading concept where we define, when a function should run or stop. A Tkinter function can be scheduled using the after(time, callback) function.Let us suppose that we have created a callback function that forces the main window to be closed after some time. There might be times when we need to stop the scheduling of the function. In order to cancel or stop a particular schedule of a callback function, we can use after_cancel(widget) function.ExampleIn the given example, the script will close the main window after 3 seconds but after initializing ...

Read More

How to set the width of a Tkinter Entry widget in pixels?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 03-May-2021 12K+ Views

Tkinter has an Entry widget to accept single-line user input. It has many properties and attributes that can be used to configure the Entry widget. To change the size (width or height of the Entry widget), we can use Internal Padding Properties – ipadx and ipady. By defining the value of internal padding, we can actually change the width and height of the Entry widget.Example#Import the required Libraries from tkinter import * from tkinter import ttk #Create an instance of tkinter frame win = Tk() #Set the geometry of tkinter frame win.geometry("750x350") #Define a function to submit the validate the ...

Read More
Showing 341–350 of 414 articles
« Prev 1 33 34 35 36 37 42 Next »
Advertisements