Found 310 Articles for GUI-Programming

How to put a border around a Frame in Python Tkinter?

Kiran Kumar Panigrahi
Updated on 28-Aug-2023 11:56:44

27K+ Views

To put a border around a Frame in Tkinter, we have to use the highlightbackground and highlightthickeness parameters while creating the Frame. Let's take an example and see how to use these two parameters.Steps −Import the tkinter library and create an instance of tkinter frame.Set the size of the frame using geometry() method.Create a frame with Frame() method. Highlight the border of the frame with a color, highlightbackground="blue". Then, set the thickness of the border, highlightthickness=2.Next, create some widgets inside the frame. In the example, we have placed four checkbuttons and a button inside the frame.Finally, run the mainloop of ... Read More

Copy from clipboard using Python and Tkinter

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 13:40:07

5K+ Views

To copy from clipboard, we can use the clipboard_get() method of Tkinter. Let's take an example and see how to get the data from the clipboard and display it on a Tkinter window.Steps −Import the tkinter library and create an instance of tkinter frame.Set the size of the frame using geometry method.Next, call clipboard_get() to get the text from the clipboard and store the data in a variable "cliptext".Create a label to the display the clipboard text. Pass cliptext as text, "text=cliptext".Finally, run the mainloop of the application window.Example# Import the tkinter library from tkinter import * # Instance ... Read More

Display the Host Name and IP Address on a Tkinter Window

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 13:37:35

638 Views

To obtain a user's IP address, we can use Python's native networking interface, socket. First of all, we need to query the device's host name and then get its associated IP address.In this example, we will use the socket library to get the host name and IP address and print the details on two labels.Steps −Import the tkinter library and create an instance of tkinter frame.Set the size of the frame using geometry method.Next, use the gethostname() method of socket library to get the host name and store it in a variable "hostname".Then use the gethostbyname() method and pass the ... Read More

How to draw a dashed line on a Tkinter canvas?

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 13:35:43

3K+ Views

To draw a dashed line on a Tkinter canvas, we can use the dash parameter of create_line() method.Steps −Import the tkinter library and create an instance of tkinter frame.Set the size of the frame using geometry method.Create a Canvas widget and set its height and width.Next, use the create_line function and pass the coordinates of the line (x1, y1) and (x2, y2).To get a dashed line, use the dash parameter dash=(5, 1) for 5px dash followed by 1px space.You can set the color and width of the dashed lines using the fill and width parameters.Finally, run the mainloop of the ... Read More

How to align checkbutton in ttk to the left side?

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 13:33:15

4K+ Views

To align the checkbuttons to left, you can use the anchor parameter and set it to "w" (west). Let's take an example and see how to do it.Steps −Import the tkinter library and create an instance of tkinter frame.Set the size of the frame using geometry method.Create a LabelFrame to collect the checkbuttons in a group.Next, create a checkbutton inside the LabelFrame and set its anchor to the West. anchor='w'.Similarly, create three more checkbuttons with their anchor set at West. It will align all the checkbuttons to the left.Finally, run the mainloop of the application window.Examplefrom tkinter import * ... Read More

How to exit from Python using a Tkinter Button?

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 13:29:39

20K+ Views

To exit from Python using a Tkinter button, you can follow the steps given below −Steps −Import the tkinter library and create an instance of tkinter frame.Set the size of the frame using geometry method.Define a function close() to close the window. Call the method win.destroy() inside close().Next, create a button and call the close() function.Finally, run the mainloop of the application window.Example# Import the library from tkinter import * # Create an instance of window win = Tk() # Set the geometry of the window win.geometry("700x350") # Title of the window win.title("Click the Button to Close ... Read More

How to place an image into a frame in Tkinter?

Kiran Kumar Panigrahi
Updated on 22-Aug-2023 16:51:03

73K+ Views

To place an image into a Tkinter frame, you can follow the steps given below −Steps −Import the required libraries and create an instance of tkinter frame. To open an image and place it inside the frame, we will use the Pillow (PIL) library.Set the size of the frame using geometry method.Create a frame and specify its height and width. Place the frame at the center of the window using place() method with anchor='center'.Open an image using ImageTk.PhotoImage(Image.open("image"))Next, create a label object inside the frame and pass the image inside the label.Finally, run the mainloop of the application windowExample# Import ... Read More

Tkinter-How to get the current date to display in a tkinter window?

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 13:24:01

6K+ Views

To display the current date in tkinter window, we will use the datetime library.date = dt.datetime.now()Steps −Import the required libraries and create an instance of tkinter frame.Set the size of the frame using geometry method.Call datetime.now() and store the value in a variable "date".Next, create a label to display the date. In the text parameter of the label, pass the date value and format the data as text=f"{date:%A, %B %d, %Y}".%A – Day of the week, full name%B – Full month name%d – Day of the month%Y – Year with century as a decimal numberFinally, run the mainloop of the ... Read More

How to display multiple labels in one line with Python Tkinter?

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 13:18:11

5K+ Views

To display multiple labels in one line with Python Tkinter, we can use the pack() method of label and align all the labels to the same side. Let's take an example and see how to display multiple labels in one line.Steps −Import the required libraries and create an instance of tkinter frame.Set the size of the frame using geometry method.Create a label and name it "Label 1". Set its font and highlight the label with a background color.Next, use the pack() method of label and set side=LEFT to force the label to position itself on the left of the screen.Similarly, ... Read More

Creating an automatically maximized tkinter window

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 13:14:28

2K+ Views

There are two different ways in which we can get an automatically maximized window in Tkinter.We can use the state() method of Tkinter and invoke it with the attribute "zoomed".root.state("zoomed")The second approach is to use the attributes method of Tkinter with the parameter "-fullscreen" and set it to True.By default, Tkinter creates a window of a predefined size. The dimensions of the window can be customized using the geometry method. For example, root.geometry("700 x 350") Example 1# Import the required libraries from tkinter import * # Create an instance of tkinter frame root=Tk() # Create a label Label(root, ... Read More

Previous 1 ... 5 6 7 8 9 ... 31 Next
Advertisements