Social Icons

Tuesday, March 27, 2018

The Graphical User Interface GUI Tkinter in Python

1 - The graphical User Interface (GUI) tkinter for Python

So far, we have only seen the Python programming under console, we can then wonder how can we manipulate windows with buttons, labels and input fields ...
Well, know that the developers of the Python language, have already thought about that. Python already integrates with its interpreter a free graphic library named Tkinter. Creating your Human Machine Interfaces with this library will allow you to have no library to download in addition to your code.
But if you want to integrate other graphic libraries, here are the most famous bibs:
  • Tkinter for Tk
  • wxPython for wxWidgets
  • PyGTK for GTK +
  • PyQt for Qt.
Note that each of these libraries has its own characteristics. As for us in this tutorial, we will limit ourselves to tkinter which is integrated in the Python language.

2 - Create a window with tkinter

2 - 1 - Create a simple window with tkinter

Tkinter is the standard GUI library for Python. Python when combined with Tkinter provides a quick and easy way to create graphical applications. Tkinter provides a powerful object-oriented interface to the Tk GUI toolbox.
Creating a GUI application using Tkinter is an easy task. All you need to do is perform the following steps:
  • Import the Tkinter module.
  • Create the main window of the GUI application.
  • Add one or more of the widgets mentioned above to the GUI application.
  • Enter the main event loop, mainloop()
Here's the code that create a simple window:
from tkinter import *
my_window = Tk()
my_window.mainloop()

What displays after execution:

2 - 2 - Add a name to the window


To add a name to the window just add the instruction:
my_window.title ("my first window") 
Here is the code that creates a window with a name: "my first window"
from tkinter import *
my_window = Tk()
my_window.title("my first window")
my_window.mainloop()

What displays after execution:


2 - 3 - Define the dimensions of the tkinter window


To define the dimensions of the window, just use the geometry() method by adding the statement:
my_window.geometry ("width x height")
Here is the code that displays a window named  "my first window" and dimension 350 x 200 :

from tkinter import *
my_window = Tk()
my_window.title("my first window")
my_window.geometry( "350x200")
my_window.mainloop()
What displays after execution:

3 Tkinter widgets

The Tkinter library provides various controls, such as buttons, labels, and text boxes used in a graphics application. These controls are commonly called widgets.
There are currently 15 types of widgets in Tkinter. Here we present the names of these widgets and a brief description:
  1. Button: the Button widget allows you to create buttons for your application.
  2. Canva: the Canva widget allows you to draw shapes, such as lines, ovals, polygons and rectangles, in your application.
  3. Checkbutton: the Checkbutton widget allows you to display a number of options in the form of check boxes. The user can select several options at the same time.
  4. Entry: the Entry widget is used to display a single line text field for accepting values ​​from a user.
  5. Frame: the Frame widget is used as a container widget to organize other widgets.
  6. Label: the Label widget is used to provide a legend or description for the other widgets. It can also contain images.
  7. Listbox: The Listbox widget is used to provide a list of options to a user.
  8. menubutton: the menubutton widget is used to display the menus in your application.
  9. Menu: The Menu widget is used to provide various commands to a user. These commands are contained in Menubutton.
  10. Message: the Message widget is used to display multi-line text fields allowing to accept the values ​​of a user.
  11. Radiobutton: the Radiobutton widget is used to display a number of options in the form of radio buttons. The user can only select one option at a time.
  12. Scale: The Scale widget is used to provide a cursor widget.
  13. Scrollbar: The Scrollbar widget is used to add scrolling functionality to various widgets, such as list boxes.
  14. Text: the Text widget is used to display text on multiple lines.
  15. Toplevel: the Toplevel widget is used to provide a separate window container.
  16. Spinbox: the Spinbox widget is a variant of the standard Tkinter Entry widget, which can be used to select a fixed number of values.
  17. PanedWindow: the PanedWindow widget is a container that can contain any number of panes, arranged horizontally or vertically.
  18. LabelFrame: a labelframe is a simple container widget. Its main purpose is to act as a divider or container for complex window layouts.
  19. tkMessageBox: this module is used to display message boxes in your applications.



Younes Derfoufi
my-courses.net

1 comment:

  1. This is my very first time that I am visiting here and I’m truly pleasurable to see everything at one place.
    ux design studios

    ReplyDelete

Category Of Mobile Courses

Actualités (644) Adsense (1) Affiliation (1) Algebraic Topology (1) Algorithmic (1) all-news (30) Android (5) Android App (8) Android app without code (4) Android Apps (168) Android Development (4) Android download (2) Android OS (3) AngularJS (1) Automata theory and formal language (5) C programming (5) Category and Functor (8) CMS (3) Computer Glossary (18) Create Mobile App With Ionic Framework (2) CSS (2) CSS-Cascading-Style-Sheets (4) Developpement Java (13) Differential Geometry (1) Django-Python-Framework (8) dropshiping (26) Earn Money by Internet (4) Emplois (23) Framework php (2) Fraud (2) HTML (7) Java For Beginners (10) Javascript (12) Kotlin Programming Language (8) Kotlin For Mobile Android (1) Linux Download (2) Marketing (5) Mobile (3) Mobile Courses (4) Mobile Marketing (4) MoneyGram (1) News (721) Node.js (5) Open Source (1) Photoshop (1) Protect Computer (1) Python (32) Python BeautifulSoup (1) Python For Data Science (2) Python-Books (6) Python-DVD-Training (1) Python-Exercises (138) Python-Framework (1) Python-IDE (1) Python-Modules (1) Python-pdf (2) Python-pyQt (1) Référencement (2) Script PHP (2) Security (6) SEO (1) Snipping Tool: Faq (1) Social Networks (1) Source Code (1) Statistics With SPSS (2) Surveillance Software (1) Travail à domicile (6) Tutoriels php en vidéos (2) Tutoriels-MySql (6) tutoriels-php (19) Utilitaires (1) VPS (1) Web Hosting (1) Webcam (1) Webmarketing (11) Western Union (1) Windows 10 (1) Windows 7 (4) Windows 7 Faq (2) Windows 8 (1) Windows Accessories (1) Windows Download (8) Windows Drivers (1) Windows Fonts (1) Windows Power Shell (2) Windows Registry (2) Windows Security (18) Windows Software (2) Windows Spyware (2) Windows utilities (3) Windows Virus (2) Windows Vista (3) Windows Wireless (1) Windows xp (1) Wordpress (1)
 

Sample text

Sample Text

 
Blogger Templates