Found 604 Articles for Tkinter

Resize the Tkinter Listbox widget when the window resizes

Dev Prakash Sharma
Updated on 22-Apr-2021 07:46:58

2K+ Views

Tkinter Listbox widgets are used to display scrollable boxes with vertically stacked menus. Within the window, the user can select either one or multiple items from the widget. In Tkinter, all the widgets are aligned either vertically or horizontally, and sometimes it seems difficult to arrange the widget position whenever we resize our window.We can configure the Listbox widget property by using expand=True and fill=BOTH property. These properties ensure that the widget stretches both vertically and horizontally. However, expand allows the widget to grow in available space.Example#Import tkinter library from tkinter import * #Create an instance of Tkinter frame or ... Read More

Removing the TK icon on a Tkinter window

Dev Prakash Sharma
Updated on 22-Apr-2021 07:46:01

935 Views

Tkinter initially displays a window that contains all the widgets and components. When we look on the Tkinter Menubar, it displays some "leaf" default icon for every Tkinter application. In order to change the default icon of the Tkinter window, we can use iconbitmap("icon location") method. It takes the location of the icon file and displays the window with a particular icon.ExampleIn this python script, we have created an icon and used it for the output window.#Import tkinter library from tkinter import * #Create an instance of tkinter frame or window win= Tk() #Set the geometry of tkinter frame win.geometry("750x250") ... Read More

PDF Viewer for Python Tkinter

Dev Prakash Sharma
Updated on 22-Apr-2021 07:41:31

5K+ Views

Python is well known for its large set of libraries and extensions, each for different features, properties and use-cases. To handle PDF files, Python provides PyPDF2 toolkit which is capable of processing, extracting, merging multiple pages, encrypting PDF files, and many more. It is a very useful Package for managing and manipulating the file streams such as PDFs. Using PyPDF2, we will create a Tkinter application that reads the PDF file by asking users to select and open a PDF file from the local directory.To create the application, we will follow the steps given below −Install the requirement by typingpip ... Read More

Opening and reading a file with askopenfilename in Tkinter?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:38:53

2K+ Views

When a user wants to open a file from a directory, the preferred way to do this is to display a popup where the user selects a file to Open. Like most tools and widgets, Tkinter provides us a way to open a dialog for opening a file, reading a file, saving a file. All these functionalities are part of filedialog Module in Python. Just like other widgets, filedialog needs to be imported explicitly in the notebook. There are certain other modules that contain the filedialog such as, askdirectory, askopenfilename, askopenfile, askopenfilenames, asksaveasfilename, etc.ExampleIn this example, we will define a ... Read More

Mouse Position in Python Tkinter

Dev Prakash Sharma
Updated on 22-Apr-2021 07:38:31

7K+ Views

Events are very useful to perform and manage multiple tasks in a large-scale application. We can bind a particular event with the keyboard buttons or mouse buttons using the bind(‘handler’, ‘callback’) method. Generally, the mouse pointer and its motion are tracked for the purpose of building a screensaver, 2D or 3D games. In order to print the coordinates of the pointer, we have to bind the Motion with a callback function that gets the position of the pointer in x and y variables.Example#Import tkinter library from tkinter import * #Create an instance of tkinter frame or window win= Tk() #Set ... Read More

How to word-wrap text in Tkinter Text?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:40:45

7K+ Views

Word Wrapping plays a significant role in any textual information. It is an important feature for any text editor which breaks the section of a particular text to fit into multiple sections of lines where possible. It is used to fit the content in the width of a text document. In Tkinter, we can wrap the words or chars in the text widget using the wrap property. The default values for the wrap properties are – WORD, CHARS, or NONE.ExampleIn this example, we will wrap all the words of a text widget using the wrap property.#Import tkinter library from tkinter ... Read More

How to set the font size of a Tkinter Canvas text item?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:35:24

4K+ Views

Canvas is one of the flexible widgets in tkinter which controls the widgets with its power of functions, methods, and attributes. However, tkinter canvas can be used to create text using the create_text(options) constructor. We can define the text along with other properties in the constructor. After defining the text, we can control over the text style such as font-family, font-size and font-style by using font(property).ExampleLet us have a look at the following example where we will add a new text and then resize it using the font property.#Import tkinter library from tkinter import * from tkinter import ttk #Create ... Read More

How to set the sticky button property properly?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:31:46

1K+ Views

Tkinter Buttons can be configured through the different available attributes and properties in Tkinter. We can add a sticky property to make it sticky relative to the window in which it is residing. The sticky property allows the widget to set the relative position in the window. To make a button sticky, we have to choose the direction or position such as N, E, S, W, NE, NW, SE, SW, and zero.Example#Import the tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkiner frame win= Tk() #Define the geometry of the function win.geometry("750x250") #Create a ... Read More

How to set font for Text in Tkinter?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:31:28

8K+ Views

Tkinter has many inbuilt methods and functions which are used to provide different features in the widgets. We can customize the font-property of text widget in a tkinter application using the font(‘font-family’, font-size, ‘style’) attribute. The tuple can be declared inside the Text constructor.ExampleLet us have a look at the following example where we will create a text widget with a customized font property. #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") #Define a text widget with font-property text= Text(win, ... Read More

How to select at the same time from two Tkinter Listbox?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:31:07

2K+ Views

Let us consider a situation for a particular system to keep selecting multiple files from a directory and, once copied in the clipboard, paste them into another directory. The idea of making multiple selections in ListBoxes can be implemented by using the exportselection property. The property prevents the selected options from losing while choosing an item from another ListBox. Thus, we can select multiple options from the ListBoxes. To configure a Listbox to behave like keep selection steady, we can make exportselection = False.Example#Import Tkinter library from tkinter import * #Create an instance of Tkinter frame or window win= Tk() ... Read More

Advertisements