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
-
Economics & Finance
GUI-Programming Articles
Page 21 of 25
How to bind events to Tkinter Canvas items?
Tkinter events can be bound with widgets to perform operations when user interactions occur. You can bind event handlers to Canvas items using the tag_bind() method, making canvas items interactive and dynamic. Binding Events to Canvas Items Use canvas.tag_bind(item_id, event, callback) to bind events to specific canvas items ? import tkinter as tk # Create window root = tk.Tk() root.title("Canvas Item Events") root.geometry("400x300") # Create canvas canvas = tk.Canvas(root, width=400, height=300, bg='white') canvas.pack() # Create canvas items circle = canvas.create_oval(50, 50, 150, 150, fill='lightblue', outline='blue', width=2) rectangle = canvas.create_rectangle(200, 50, 300, 150, fill='lightgreen', ...
Read MoreHow to specify where a Tkinter window should open?
Tkinter allows you to control where a window appears on screen using the geometry() method. The geometry method accepts a string format: "widthxheight+x_offset+y_offset" to set both size and position. Syntax window.geometry("widthxheight+x_offset+y_offset") Where: width, height − Window dimensions in pixels x_offset, y_offset − Position from top-left corner of screen Example Here's how to create a window that opens at position (300, 300) ? # Import the required libraries from tkinter import * # Create an instance of Tkinter Frame win = Tk() # Set the geometry win.geometry("700x350+300+300") ...
Read MoreWord Dictionary using Python Tkinter
In this article, we will create a GUI-based dictionary using PyDictionary and Tkinter modules. This application will allow users to search for word meanings through an intuitive graphical interface. PyDictionary is a Python module that helps to get meanings, translations, antonyms and synonyms of words. It uses WordNet for getting meanings, Google for translations, and synonym.com for getting synonyms and antonyms. PyDictionary uses BeautifulSoup and Requests modules as dependencies. Installation First, install the required module using pip ? pip install PyDictionary Creating the Dictionary Application Here's the complete code to create a ...
Read MoreWindow Resizer Control Panel in Tkinter
In this article, we will create a GUI-based window resizer control panel using Tkinter that allows you to resize a target window by adjusting its width and height through sliders. We'll use the ttk library from Tkinter to create the sliders and build a control panel that can launch a new window and dynamically resize it using three different controls: width-only, height-only, and proportional resizing. Creating the Basic Control Panel Let's start by creating the main window with the control interface − # Import the required Libraries from tkinter import * from tkinter import ttk ...
Read MoreWhat does the 'tearoff' attribute do in a Tkinter Menu?
The tearoff attribute in Tkinter Menu controls whether a menu can be "torn off" or detached from its parent window. When enabled, users can separate the menu into a floating window for easier access. Tearoff Options The tearoff attribute accepts a Boolean value with two behaviors: tearoff=0 − Menu remains attached to the parent window (default) tearoff=1 − Menu displays a dashed separator line at the top, allowing users to detach it Example: Non-Tearable Menu Here's how to create a menu that stays attached to the window: import tkinter as tk ...
Read MoreTkinter bell() method
Tkinter bell() method produces the default system sound or beep. This method can be invoked on any Tkinter widget to trigger the system's default notification sound. You can customize the system sound through your operating system's sound settings. Syntax widget.bell() Where widget can be any Tkinter widget like root window, Frame, Button, etc. Example Let's create a simple application with a button that plays the system bell sound when clicked − # Import the library from tkinter import * # Create an instance of tkinter frame win = Tk() ...
Read MoreRatio Calculator GUI using Tkinter
In this article, we will see how to create a functional GUI application that calculates ratios using Python's Tkinter library. We will use the Spinbox widget that creates an ideal spinner for numeric values. The Spinbox allows users to select values within a specified range by either typing directly or using up/down arrows. We'll build a ratio calculator that solves for the fourth term in a proportion: if a:b = c:x, then x = (b×c)/a. Creating the Ratio Calculator Let's create a complete tkinter application with spinboxes for input values and a button to perform the calculation ...
Read MorePython program to find the sum of sine series
Let us consider that we have a value x and we need to calculate the sum of the sine(x) series. The sine series is represented mathematically as: sine(x) = x - x³/3! + x⁵/5! - x⁷/7! + x⁹/9! - ... To solve this series-based problem, we will take the degree as input, convert it to radians, and then iterate through the terms to calculate the sum using the mathematical formula. Approach Take input of the number of terms and degree value. Convert degree to radians using the formula: radians = degrees × π/180 ...
Read MorePython program to calculate the number of digits and letters in a string
Sometimes we need to count the number of digits and letters in a string separately. Python provides built-in methods like isdigit() and isalpha() to identify character types easily. Example Input and Output Input − s = "tutorialsP0int" Output − Letters: 13 Digits: 1 Explanation − The string contains 13 alphabetic characters and 1 numeric digit. Approach To count letters and digits in a string, we iterate through each character and use Python's built-in string methods: Initialize counters for letters and digits Loop through each character in ...
Read MoreOn/Off Toggle Button Switch in Tkinter
Creating an on/off toggle button in Tkinter is useful for implementing features like dark mode, settings toggles, or any binary state controls. This involves changing button images and associated text when clicked. Basic Toggle Button Structure A toggle button requires three key components: a state variable, images for both states, and a function to switch between them ? import tkinter as tk from tkinter import ttk # Create main window root = tk.Tk() root.title('Toggle Button Demo') root.geometry('400x200') # State variable is_on = True # Toggle function def toggle(): global ...
Read More