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 5 of 42
Save File Dialog Box in Tkinter
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 MoreHow to create a Tkinter error message box?
The Tkinter library has many built-in functions and methods which can be used to implement the functional part of an application. We can use messagebox module in Tkinter to create various popup dialog boxes. The messagebox property has different types of built-in popup windows that the users can use in their applications.If you need to display the error messagebox in your application, you can use showerror("Title", "Error Message") method. This method can be invoked with the messagebox itself.Example# Import the required libraries from tkinter import * from tkinter import messagebox # Create an instance of tkinter frame or window ...
Read MoreHow to reconfigure Tkinter canvas items?
Using the Canvas widget, we can create text, images, graphics, and visual content to add to the Canvas widget. If you need to configure the Canvas item dynamically, then tkinter provides itemconfig(**options) method. You can use this method to configure the properties and attributes of the Canvas items. For example, if we create a line inside the Canvas widget, we can configure its color or width using itemconfig() method.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win = Tk() # Set the size of the tkinter window win.geometry("700x350") ...
Read MoreHow to set justification on Tkinter Text box?
The Text widget supports multiline user input from the user. We can configure the Text widget properties such as its font properties, text color, background, etc., by using the configure() method.To set the justification of our text inside the Text widget, we can use tag_add() and tag_configure() properties. We will specify the value of "justify" as CENTER.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set the size of the tkinter window win.geometry("700x350") # Create a text widget text=Text(win, width=40, height=10) # justify the text ...
Read MoreHow to get the widget name in the event in Tkinter?
Tkinter is a Python library that is used to create and develop functional GUI-based applications. Tkinter provides widgets that can be used for constructing the visual and functional representation of the application.Let us suppose that we have defined some widgets in our application. If we want to get a widget's name in an event, then it can be achieved by using event.widget["text"] keywords inside a function. We can print the name by using it inside the print() function.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set ...
Read MoreHow to delete lines from a Python tkinter canvas?
The Canvas widget has many use-cases in GUI application development. We can use a Canvas widget to draw shapes, creating graphics, images, and many other things. To draw a line in Canvas, we can use create_line(x, y, x1, y1, **options) method. In Tkinter, we can draw two types of lines − simple and dashed.If you want your application to delete the created lines, then you can use the delete() method.ExampleLet us have a look at the example where we will delete the line defined in the Canvas widget.# Import the required libraries from tkinter import * # Create an ...
Read MoreHow to insert the current time in an Entry Widget in Tkinter?
To work with the date and time module, Python provides the 'datetime' package. Using the 'DateTime' package, we can display the date, manipulate the datetime object and use it to write the additional functionality in the application.To display the current date in a Tkinter window, we've to first import the datetime module in our environment. Once imported, you can create an instance of its object and display it using the Entry widget.ExampleHere is an example of how you can show the current date in an Entry widget.# Import the required libraries from tkinter import * import datetime as dt ...
Read MoreHow to display an image/screenshot in a Python Tkinter window without saving it?
Tkinter is a standard Python library that is used to create and develop GUI-based applications. To display an image, we use the PIL or Pillow library.Let us suppose that we want to create an application that will take a screenshot of the window and display the captured image in another window. To achieve this, we can follow the steps given below −Import the required libraries.Create a universal button to take the screenshot.Define a function to take the screenshot.In the given function, define the coords and region through which we want to take the screenshot.Create a Toplevel window and define a ...
Read MoreHow to change Entry.get() into an integer in Tkinter?
The Entry widget in Tkinter is generally used to accept one-line input in the text field. We can get the output from the Entry widget using .get() method. However, the .get() method returns the output in string format. For example, if the user types an integer number in the Entry widget, it gets converted to a string. To change the type of the Entry input into an integer, we can cast the string to an integer.ExampleIn this example, we have shown how to calculate the sum while taking an integer input from the user.# Import the required libraries from tkinter ...
Read MoreHow to configure default Mouse Double-Click behavior in a Tkinter text widget?
The Text widget in Tkinter is used to add a text editor-like functionality in the application. The Text widget supports multiline user input from the user. We can configure the text widget properties such as its font properties, text color, background, etc., by using the configure() method.The Text widget also provides tagging through which we can make a selection of text. To extend this functionality, we can also bind the Double-Click button that will possess the event for selecting a Word at a time.ExampleLet us have a look at the example, where we have disabled the double mouse-click button to ...
Read More