Found 604 Articles for Tkinter

Changing ttk Button Height in Python

Dev Prakash Sharma
Updated on 21-Apr-2021 07:32:52

2K+ Views

Ttk adds styles to the tkinter’s standard widget which can be configured through different properties and functions. We can change the height of the ttk button by using the grid(options) method. This method contains various attributes and properties with some different options. If we want to resize the ttk button, we can specify the value of internal padding such as ipadx and ipady.ExampleLet us understand it with an example, #Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame or window win = Tk() #Set the geometry of tkinter frame win.geometry("750x250") #Create a ... Read More

When and how to use pack or grid layouts in tkinter?

Dev Prakash Sharma
Updated on 16-Apr-2021 07:25:26

2K+ Views

Tkinter Pack geometry manager is the bounding box for all the widgets. It helps the parent widget to hold and display all the containing widgets in it. It is easy to use and we can display any widgets by using the pack() method. Additionally, pack manager has several other properties like side, fill, expand, anchor, and padding which can be used to style the widgets in an application.There is another useful way to hold and represent the widgets in a twodimensional table that is divided into rows and columns. Each row and column is made up of a Cell and ... Read More

What does 'weight' do in tkinter?

Dev Prakash Sharma
Updated on 16-Apr-2021 07:23:57

1K+ Views

In order to structure the layout of the widgets in an application, we generally use the tkinter grid system. A grid system comprises rows and columns in which widgets are aligned. If we want to configure any widgets, then we can use the grid row and columns properties.Consider, if a widget is aligned such that there is extra space left, then we can add the weight property which enables the column to grow. A non-zero weight enables the column width to grow in the screen size if there is any extra space left. However, if the weight is zero, then ... Read More

Update Tkinter Label from variable

Dev Prakash Sharma
Updated on 16-Apr-2021 07:22:47

4K+ Views

To display the text and images in an application window, we generally use the Tkinter Label widget. In this example, we will update the Label information by defining a variable. Whenever the information stored in the variable changes, it will update the Label as well. We can change the Label information while defining the textvariable property in the Label widget.Example#Import the required library from tkinter import * #Create an instance of tkinter frame win = Tk() win.geometry("750x250") #Create a String Object and set the default value var = StringVar() #Create a text label label = Label(win, textvariable = var, font=('Helvetica ... Read More

Underline Text in Tkinter Label widget

Dev Prakash Sharma
Updated on 16-Apr-2021 07:21:09

6K+ Views

Tkinter label widgets can be styled using the predefined attributes and functions in the library. Labels are useful in place of adding text and displaying images in the application. Sometimes, we need to style the font property of Label Text such as fontfamily, font-style (Bold, strike, underline, etc.), font-size, and many more. If we want to make the label text underlined, then we can use the underline property in the font attribute.Example#Import the required library from tkinter import* #Create an instance of tkinter frame win= Tk() #Define geometry of the window win.geometry("750x250") #Create a Label widget label= Label(win, text= "Hey, ... Read More

Tkinter scrollbar for frame

Dev Prakash Sharma
Updated on 16-Apr-2021 07:19:55

15K+ Views

Let’s suppose you want to organize a set of widgets inside an application window, then you can use Frames. Tkinter Frames are generally used to organize and group many widgets. For a particular application, we can also add a scrollbar in the frames. In order to add a scrollbar, we generally use to the Scrollbar(...options) function.Example#Import the required library from tkinter import * #Create an instance of tkinter frame or window win = Tk() #Define the geometry win.geometry("750x400") #Create a Frame frame= Frame(win) def close():    win.destroy() #Create a Label widget in the frame text= Label(frame, text= "Register", font= ('Helvetica ... Read More

Setting the focus to a specific Tkinter entry widget

Dev Prakash Sharma
Updated on 16-Apr-2021 07:18:08

2K+ Views

Tkinter has many universal methods that add functionalities to widgets and elements. In order to set the focus to a particular widget, we have the focus_set() method which is used to focus a specific widget in a group of widgets present in an application.ExampleIn this example, we have created numeric keys in the range 0-9. We have set the focus for Numeric key ‘2’.#Import the required libraries from tkinter import * import webbrowser #Create an instance of tkinter frame win = Tk() win.geometry("750x400") #Define function for different operations def close():    win.destroy() #Create a Label widget text=Label(win, text="", font=('Helvetica bold ... Read More

Select all text in a Text widget using Python 3 with tkinter

Dev Prakash Sharma
Updated on 16-Apr-2021 07:16:35

2K+ Views

Tkinter text widgets are used for creating text fields that contain multiline user input. It has many inbuilt functions and methods which can be invoked to perform certain operations on text widgets. In contrast, let us assume that we have written a bunch of context in the text widget and if we want to select all the text, then we can use tag_add(tag, range) to select the text and add tag and tag_configure(tag, options) to style the tag property.Example#Import tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("750x200") def select_text(): ... Read More

Resizing pictures in PIL in Tkinter

Dev Prakash Sharma
Updated on 16-Apr-2021 07:14:47

579 Views

Python provides Pillow or PIL package for image processing which is used to load, process, and customize the images in an application. It has many properties like Color of the image, Image Font, resizing the images, loading the image, etc.In order to resize the Images in an application, we can use the resize(width, height) method. The method can be invoked after loading the image in the application. In order to open the image in the application, we have to import the package in the notebook as, from PIL import Image, ImageTkExampleIn the following example, we have resized an image to ... Read More

Save File Dialog Box in Tkinter

Dev Prakash Sharma
Updated on 20-Aug-2021 16:20:01

11K+ Views

We often use Open and Save Dialog. They are common across many applications and we already know how these dialogs work and behave. For instance, if we click on open, it will open a dialog to traverse the location of the file. Similarly, we have the Save Dialog.We can create these dialogs using Python tkFileDialog package. In order to work with the package, we have to import this in our environment.Type the following command to import the tkFileDialog package in the notebook, from tkinter.filedialog import asksaveasfileExampleIn this example, we will create an application that will save the file using the ... Read More

Advertisements