Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Dev Prakash Sharma
Page 15 of 42
How to add a margin to a tkinter window?
The margin of a tkinter window can be controlled by specifying the value of fill, expand and padding. Another way to set the margin of a tkinter window is to use grid(**options) Geometry Manager. Grid pack manager allows us to add the margin by specifying the value of row and column property.Example# Import the required library from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win= Tk() # Set the size of the Tkinter window win.geometry("700x350") # Add a frame to set the size of the window frame= Frame(win, relief= 'sunken', ...
Read MoreHow do you create a Tkinter GUI stop button to break an infinite loop?
Tkinter is a Python library which is used to create GUI-based application. Let us suppose that we have to create a functional application in which a particular function is defined in a loop. The recursive function will display some text in a Label widget for infinite times.To stop this recursive function, we can define a function which changes the condition whenever a button is clicked. The condition can be changed by declaring a global variable which can be either True or False.Example# Import the required library from tkinter import * # Create an instance of tkinter frame win= Tk() ...
Read MorePython Tkinter – Set Entry width 100%
Tkinter Entry widgets accept single-line user input in a text field. We can change the properties of the Entry widget by providing the default attributes and values in its constructor.Let us suppose that we want to create a full-width Entry widget for an application. There are several ways to do that but if we consider the simplest case where we use Pack Geometry Manager to display the Entry widget, then we can definitely set the width of Entry widget by adding fill(x or y) property.Example# Import the required library from tkinter import * from tkinter import ttk # Create ...
Read MoreHow to create hyperlink in a Tkinter Text widget?
Tkinter Text widgets are generally used for accepting multiline user input in the given text field. For a particular text document, the content may contain hyperlinks too which is useful in case we want to redirect the user. You can create hyperlinks within the text widget by using HyperLinkManager snippet in Python.The HyperLinkManager code snippet adds the hyperlink on the keyword within the text widget. Once the snippet has been downloaded, you can import it in the notebook by typing "from tkHyperLinkManager import HyperlinkManager"Example# Import the required libraries from tkinter import * from tkHyperLinkManager import HyperlinkManager import webbrowser from functools ...
Read MoreUsing OpenCV with Tkinter
Open CV is a Python library that is used to work with Computer Vision and other artificial artifacts. Open CV has inbuilt functions and methods which provide access to work with Computer Vision in Artificial Intelligence and Machine Learning. Some of the examples of Open CV are: face detection, object detection, X-ray and other industrial uses.Using Tkinter Library, we can create an interactive application that uses OpenCV as the essential part of the application.To create the application, you are required to install OpenCV in your local machine and make sure that Python Pillow package is pre-installed. You can install these ...
Read MoreWhat is a better Tkinter geometry manager than .grid()?
The Geometry Manager is one of the specific features in the Tkinter Library. It provides structure to all the Tkinter widgets in the window. The Geometry Manager is used for formatting the layout and position of the widget in a Tkinter application window.To format the look and appearance of any widget, we have three general methods in Geometry Manager.Pack Geometry ManagerGrid Geometry ManagerPlace Geometry ManagerEach Geometry Manager has some features that provide a different style and layout to the widgets. The Pack Geometry Manager is the most commonly used layout manager which gives access to add padding, margin, fill and ...
Read MoreInheriting from Frame or not in a Tkinter application
In the Object-Oriented Programming Paradigm, Inheritance is used for acquiring the properties of the base class and using them in a derived class. Considering the case for a Tkinter application, we can inherit all the properties of a frame defined in a base class such as background color, foreground color, font properties, etc., into a derived class or a frame.In order to support Inheritance, we have to define a class that contains some basic properties of a frame such as height, width, bg, fg, font, etc.Example# Import Tkinter Library from tkinter import * # Create an instance of Tkinter ...
Read MoreCreating scrollable Listbox within a grid using Tkinter
A Listbox widget displays a list of items such as numbers list, items list, list of employees in a company, etc. There might be a case when a long list of items in a Listbox needs a way to be viewed inside the window. For this purpose, we can attach scrollbars to the Listbox widget by initializing the Scrollbar() object. If we configure and attach the Listbox with the scrollbar, it will make the Listbox scrollable.ExampleIn this example, we will create a Listbox with a list of numbers ranging from 1 to 100. The Listbox widget has an associated Scrollbar ...
Read MoreCall a Function with a Button or a Key in Tkinter
Let assume that we want to call a function whenever a button or a key is pressed for a particular application. We can bind the function that contains the operation with a button or key using the bind(', ' callback_function) method. Here, you can bind any key to the event or function that needs to be called.ExampleIn this example, we have created a function that will open a dialog box whenever we click a button.#Import the required libraries from tkinter import * from tkinter import ttk from tkinter import messagebox #Create an instance of Tkinter Frame win = Tk() ...
Read MoreHow to clear Text widget content while clicking on the Entry widget itself in Tkinter?
Tkinter Text widget is an Input widget that supports multiline user input. It is also known as Text Editor which allows users to write the content and data in it. The content of the text widget can be cleared by defining the delete(0, END) command. Similarly, we can clear the content by clicking the Entry widget itself. This can be achieved by binding the function with a click event.Example#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry of Tkinter Frame win.geometry("700x250") #Define a function to clear ...
Read More