Hello world python tkinter

Hello world python tkinter

Widgets

  • Python | Creating a button in tkinter
  • Python | Add style to tkinter button
  • Python | Add image on a Tkinter button
  • Python Tkinter – Label
  • Python Tkinter | Create LabelFrame and add widgets to it
  • RadioButton in Tkinter | Python
  • Python Tkinter – Checkbutton Widget
  • Python Tkinter – Canvas Widget
  • Python Tkinter | Create different shapes using Canvas class
  • Python Tkinter | Create different type of lines using Canvas class
  • Python Tkinter | Moving objects using Canvas.move() method
  • Combobox Widget in tkinter | Python
  • maxsize() method in Tkinter | Python
  • minsize() method in Tkinter | Python
  • resizable() method in Tkinter | Python
  • Python Tkinter – Entry Widget
  • Tkinter – Read only Entry Widget
  • Python Tkinter – Text Widget
  • Python Tkinter – Message
  • Python | Menu widget in Tkinter
  • Python Tkinter – Menubutton Widget
  • Python Tkinter – SpinBox
  • Progressbar widget in Tkinter | Python
  • Python-Tkinter Scrollbar
  • Python Tkinter – ScrolledText Widget
  • Python Tkinter – ListBox Widget
  • Scrollable ListBox in Python-tkinter
  • Python Tkinter – Frame Widget
  • Scrollable Frames in Tkinter
  • How to make a proper double scrollbar frame in Tkinter
  • Python Tkinter – Scale Widget
  • Hierarchical treeview in Python GUI application
  • Python-Tkinter Treeview scrollbar
  • Python Tkinter – Toplevel Widget
  • Python | askopenfile() function in Tkinter
  • Python | asksaveasfile() function in Tkinter
  • Python – Tkinter askquestion Dialog
  • Python Tkinter – MessageBox Widget
  • Create a Yes/No Message Box in Python using tkinter
  • Change the size of MessageBox – Tkinter
  • Different messages in Tkinter | Python
  • Change Icon for Tkinter MessageBox
  • Python – Tkinter Choose color Dialog
  • Popup Menu in Tkinter
Читайте также:  Java string конец строки

Geometry Management

Binding Functions

Working with Images in Tkinter

Tkinter Advance

  • Getting screen’s height and width using Tkinter | Python
  • Python | How to dynamically change text of Checkbutton
  • Python | focus_set() and focus_get() method
  • Search String in Text using Python-Tkinter
  • Autocomplete ComboBox in Python-Tkinter
  • Autohiding Scrollbars using Python-tkinter
  • Python Tkinter – Validating Entry Widget
  • Tracing Tkinter variables in Python
  • Python | setting and retrieving values of Tkinter variable
  • Tkinter | Adding style to the input text using ttk.Entry widget
  • Python | after method in Tkinter
  • destroy() method in Tkinter | Python
  • Text detection using Python
  • Python | winfo_ismapped() and winfo_exists() in Tkinter
  • Collapsible Pane in Tkinter | Python
  • Creating a multiple Selection using Tkinter
  • Creating Tabbed Widget With Python-Tkinter
  • Open a new Window with a button in Python-Tkinter
  • Cryptography GUI using python

Applications and Projects

  • Python | Simple GUI calculator using Tkinter
  • Create Table Using Tkinter
  • Python | GUI Calendar using Tkinter
  • File Explorer in Python using Tkinter
  • Python | ToDo GUI Application using Tkinter
  • Python: Weight Conversion GUI using Tkinter
  • Python: Age Calculator using Tkinter
  • Python | Create a GUI Marksheet using Tkinter
  • Python | Loan calculator using Tkinter
  • Python | Create a digital clock using Tkinter
  • Make Notepad using Tkinter
  • Color game using Tkinter in Python
  • Python | Simple FLAMES game using Tkinter
  • Simple registration form using Python Tkinter
  • How to create a COVID19 Data Representation GUI?

Widgets

  • Python | Creating a button in tkinter
  • Python | Add style to tkinter button
  • Python | Add image on a Tkinter button
  • Python Tkinter – Label
  • Python Tkinter | Create LabelFrame and add widgets to it
  • RadioButton in Tkinter | Python
  • Python Tkinter – Checkbutton Widget
  • Python Tkinter – Canvas Widget
  • Python Tkinter | Create different shapes using Canvas class
  • Python Tkinter | Create different type of lines using Canvas class
  • Python Tkinter | Moving objects using Canvas.move() method
  • Combobox Widget in tkinter | Python
  • maxsize() method in Tkinter | Python
  • minsize() method in Tkinter | Python
  • resizable() method in Tkinter | Python
  • Python Tkinter – Entry Widget
  • Tkinter – Read only Entry Widget
  • Python Tkinter – Text Widget
  • Python Tkinter – Message
  • Python | Menu widget in Tkinter
  • Python Tkinter – Menubutton Widget
  • Python Tkinter – SpinBox
  • Progressbar widget in Tkinter | Python
  • Python-Tkinter Scrollbar
  • Python Tkinter – ScrolledText Widget
  • Python Tkinter – ListBox Widget
  • Scrollable ListBox in Python-tkinter
  • Python Tkinter – Frame Widget
  • Scrollable Frames in Tkinter
  • How to make a proper double scrollbar frame in Tkinter
  • Python Tkinter – Scale Widget
  • Hierarchical treeview in Python GUI application
  • Python-Tkinter Treeview scrollbar
  • Python Tkinter – Toplevel Widget
  • Python | askopenfile() function in Tkinter
  • Python | asksaveasfile() function in Tkinter
  • Python – Tkinter askquestion Dialog
  • Python Tkinter – MessageBox Widget
  • Create a Yes/No Message Box in Python using tkinter
  • Change the size of MessageBox – Tkinter
  • Different messages in Tkinter | Python
  • Change Icon for Tkinter MessageBox
  • Python – Tkinter Choose color Dialog
  • Popup Menu in Tkinter
Читайте также:  What does css do in website

Geometry Management

Binding Functions

Working with Images in Tkinter

Tkinter Advance

  • Getting screen’s height and width using Tkinter | Python
  • Python | How to dynamically change text of Checkbutton
  • Python | focus_set() and focus_get() method
  • Search String in Text using Python-Tkinter
  • Autocomplete ComboBox in Python-Tkinter
  • Autohiding Scrollbars using Python-tkinter
  • Python Tkinter – Validating Entry Widget
  • Tracing Tkinter variables in Python
  • Python | setting and retrieving values of Tkinter variable
  • Tkinter | Adding style to the input text using ttk.Entry widget
  • Python | after method in Tkinter
  • destroy() method in Tkinter | Python
  • Text detection using Python
  • Python | winfo_ismapped() and winfo_exists() in Tkinter
  • Collapsible Pane in Tkinter | Python
  • Creating a multiple Selection using Tkinter
  • Creating Tabbed Widget With Python-Tkinter
  • Open a new Window with a button in Python-Tkinter
  • Cryptography GUI using python

Applications and Projects

  • Python | Simple GUI calculator using Tkinter
  • Create Table Using Tkinter
  • Python | GUI Calendar using Tkinter
  • File Explorer in Python using Tkinter
  • Python | ToDo GUI Application using Tkinter
  • Python: Weight Conversion GUI using Tkinter
  • Python: Age Calculator using Tkinter
  • Python | Create a GUI Marksheet using Tkinter
  • Python | Loan calculator using Tkinter
  • Python | Create a digital clock using Tkinter
  • Make Notepad using Tkinter
  • Color game using Tkinter in Python
  • Python | Simple FLAMES game using Tkinter
  • Simple registration form using Python Tkinter
  • How to create a COVID19 Data Representation GUI?

Источник

Tkinter Hello, World!

Summary: in this tutorial, you’ll learn step by step how to develop the Tkinter “Hello, World!” program.

Creating a window

The following program shows how to display a window on the screen:

import tkinter as tk root = tk.Tk() root.mainloop()Code language: Python (python)

If you execute the program, you’ll see the following window:

Читайте также:  Выравнивание

First, import the tkinter module as tk to the program:

import tkinter as tkCode language: Python (python)

Second, create an instance of the tk.Tk class that will create the application window:

root = tk.Tk()Code language: Python (python)

By convention, the main window in Tkinter is called root . But you can use any other name like main .

Third, call the mainloop() method of the main window object:

root.mainloop()Code language: Python (python)

The mainloop() keeps the window visible on the screen. If you don’t call the mainloop() method, the window will display and disappear immediately. It will be so fast that you may not see its appearance.

Also, the mainloop() method keeps the window displaying and running until you close it.

Typically, you place the call to the mainloop() method as the last statement in a Tkinter program, after creating the widgets.

Troubleshooting

The tkinter module is a built-in Python module. But sometimes, it is not the case. For example, on Ubuntu, you may get the following error:

ImportError: No module named TkinterCode language: JavaScript (javascript)

In this case, you need to install tkinter module using the following command line:

sudo apt-get install python3-tkCode language: JavaScript (javascript)

Displaying a label

Now, it’s time to place a component on the window. In Tkinter , components are called widgets.

The following adds a label widget to the root window:

import tkinter as tk root = tk.Tk() # place a label on the root window message = tk.Label(root, text="Hello, World!") message.pack() # keep the window displaying root.mainloop()Code language: Python (python)

Note that you’ll learn more about the Label widget in the upcoming tutorial.

If you run the program, you’ll see the following output:

Tkinter Hello World

To create a widget that belongs to a container, you use the following syntax:

widget = WidgetName(container, **options)Code language: Python (python)
  • The container is the parent window or frame where you want to place the widget.
  • The options is one or more keyword arguments that specify the configurations of the widget.

In the program, the following creates a Label widget placed on the root window:

message = tk.Label(root, text="Hello, World!")Code language: Python (python)

And the following statement positions the Label on the main window:

message.pack()Code language: Python (python)

Note that you’ll learn more about the pack() method later. If you don’t call the pack() method, the Tkinter still creates the widget. However, the widget is invisible.

Fixing the blur UI on Windows

If you find the text and UI are blurry on Windows, you can use the ctypes Python library to fix it.

First import the ctypes module:

from ctypes import windllCode language: Python (python)

Second, call the SetProcessDpiAwareness() function:

windll.shcore.SetProcessDpiAwareness(1)Code language: Python (python)

If you want the application to run across platforms such as Windows, macOS, and Linux, you can place the above code in a try. finally block:

try: from ctypes import windll windll.shcore.SetProcessDpiAwareness(1) finally: root.mainloop()Code language: JavaScript (javascript)

Summary

  • Import tkinter module to create a Tkinter desktop application.
  • Use Tk class to create the main window and call the mainloop() method to keep the window displays.
  • In Tkinter, components are called widgets.

Источник

Оцените статью