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
Python Articles
Page 542 of 852
How to change the color of a Tkinter rectangle on clicking?
The Canvas widget is one of the most versatile widgets in the Tkinter Library. It is used for creating shapes of different types and sizes, animating objects, visualizing graphics, and many more. To change the property of a particular item in Tkinter, we can use itemconfig(**options) method. It takes options such as background color, outline color, and other useful properties of the items defined in a canvas.ExampleIn this example, we will create a rectangle such that the color inside the rectangle would change after clicking a Button.# Import the required libraries from tkinter import * from tkinter import ttk ...
Read MoreHow to create transparent widgets using Tkinter?
A Tkinter widget in an application can be provided with Transparent background. The background property of any widget is controlled by the widget itself.However, to provide a transparent background to a particular widget, we have to use wm_attributes('transparentcolor', 'colorname') method. It works in the widget only after adding the same transparent color as the background color of the widget.Example#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x250") #Adding transparent background property win.wm_attributes('-transparentcolor', '#ab23ff') #Create a Label Label(win, text= "This is a New line Text", font= ...
Read MoreHow to get the input from a Checkbox in Python Tkinter?
A checkbox widget is an input widget that has two values, either True or False. A checkbox is useful in many applications where a particular value needs to be validated.Let us suppose that we want to get the Input value from a checkbox such that if it is selected, then print the selected value. To print the value of the selected checkbox, we can use the get() method. It returns the input value of a particular widget.Example# Import Tkinter library from tkinter import * # Create an instance of tkinter frame win = Tk() # Set the geometry of ...
Read MoreChanging the Default Font for all the widgets in Tkinter
Let us consider a case where we want to change the default font of a Tkinter application. To apply the font and setting it as the default font for a particular application, we have to use option_add(**options) method where we specify a property such as background color, font, etc. The changes made after defining the method will force all the widgets to inherit the same property.ExampleIn the given script, we have set a default font for the application such that it can be used for all the widgets defined in the application.#Import the required libraries from tkinter import * ...
Read MoreConfigure tkinter/ttk widgets with transparent backgrounds
Tkinter has many feature attributes and properties to frame the structure of an application and configure the widget. In this article, we will see how to set Tkinter widgets with a transparent background. The wm_attributes('-transparentcolor', 'color') method is used for providing the transparent background to the widget.ExampleIn this example, we will create a Label widget with transparent background.#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x350") #Adding transparent background property win.wm_attributes('-transparentcolor', '#ab23ff') #Create a Label Label(win, text= "Hello World!", font= ('Helvetica 18'), bg= '#ab23ff').pack(ipadx= 50, ...
Read MoreHow to remove the dashed line from the Tkinter menu UI?
A Menu Bar contains vertically stacked menu items. We can create a Menu bar by initializing the object of Menu(root). Whenever we initialize a Menu bar in an application, it displays a line separator at the top of the Menu Bar.To remove the separator or the dashed line from the Menu, we can use the tearoff property. It can be created by defining the 'tearoff = off' property.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("750x250") win.title("Editor") # Adding ...
Read MoreHow to get the width of the Tkinter widget?
Tkinter widgets are supposed to be present in the Tkinter application window. All the widgets can be configured and customized by using predefined properties or functions.To get the width of a widget in a Tkinter application, we can use winfo_width() method. It returns the width of the widget which can be printed later as the output.Example#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x350") #Set the default color of the window win.config(bg='#aad5df') #Create a Label to display the text label=Label(win, text= "Hello World!", font= ...
Read MoreRead an image with OpenCV and display it with Tkinter
OpenCV is an Open Source Computer Vision library in Python which is widely used for Research purposes in Artificial Intelligence and Machine Learning. Computer Vision Library such as OpenCV deals with image processing. We can use OpenCV to read an image and further use it for development.Let us suppose that we want to create an application that reads an image and displays it in the window using OpenCV.Install OpenCV by using the following command −pip install opencv-pythonNext, follow the steps given below −Install OpenCV in the environment and import the library using import cv2.Import NumPy and PIL (Pillow Package) for image calculation.Load ...
Read MoreHide the console of an .exe file created with PyInstaller in Tkinter
To convert a standard Tkinter application into a window executable file, we generally use thePyintsaller package. It converts the application file into an executable application. However, we notice that when we open the executable (or .exe) file, it displays a command shell before opening the application window. We can hide or avoid the console by specifying pyinstaller --oneline filename --windowed command.ExampleIn this example, we will create an .exe file of the following program using PyInstaller.app.py#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x350") #Set the ...
Read MoreHow to remove the title bar in a Tkinter window without using overrideredirect() method?
To remove the title bar of a Tkinter window, we can use wm_attributes('type', 'value') method by specifying the type of property. In the following example, we will use 'fullscreen', a Boolean value that removes the title bar of the window.Example#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() win.geometry("700x350") #Create a Label to print the Name label= Label(win, text="This is a New Line Text", font= ('Helvetica 14 bold'), foreground= "red3") label.pack() win.wm_attributes('-fullscreen', 'True') win.mainloop()OutputRunning the above code will display a fullscreen window without the title bar.
Read More