0% found this document useful (0 votes)
49 views

Introduction To Pytohon in GUI

This document provides an introduction to Tkinter, the standard GUI library for Python. It discusses what Tkinter is and how it can be used to build desktop applications with interfaces like buttons, menus and text fields. It also introduces the IDLE integrated development environment, which is bundled with Python and provides an example of Tkinter in use.

Uploaded by

arroganciah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Introduction To Pytohon in GUI

This document provides an introduction to Tkinter, the standard GUI library for Python. It discusses what Tkinter is and how it can be used to build desktop applications with interfaces like buttons, menus and text fields. It also introduces the IDLE integrated development environment, which is bundled with Python and provides an example of Tkinter in use.

Uploaded by

arroganciah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Introduction to Tkinter

Welcome, Python coder! If you've learned the basics of Python


and want to start designing powerful GUI applications.

By now, you have no doubt experienced the power and simplicity of


Python. Perhaps you've written web services, performed data
analysis, or administered servers. Perhaps you've written a game,
automated routine tasks, or simply played around with code. But
now you're ready to tackle the GUI.

With so much emphasis on web, mobile, and server-side


programming, the development of simple desktop GUI applications
seems increasingly like a lost art; many otherwise experienced
developers have never learned to create one. What a tragedy!
Desktop computers still play a vital role in work and home
computing, and the ability to build simple, functional applications
for this ubiquitous platform should be a part of every software
developer's toolbox. Fortunately, for Python coders, that ability is
well within reach thanks to Tkinter.

https://www.tutorialspoint.com/pyqt5/pyqt5_using_qt_designer.htm
Tkinter is Python's standard GUI (Graphical User Interface) package.
tkinter provides us with a variety of common GUI elements which we
can use to build out interface – such as buttons, menus and
various kind of entry fields and display areas. We call these
elements Widgets.

Introducing Tkinter and Tk

The Tk widget library originates from the Tool Command


Language(Tcl) programming language. Tcl and Tk were created by
John Ousterman while he was a professor at Berkeley in the late
1980s as an easier way to program engineering tools being used at
the University. Because of its speed and relative simplicity, Tcl/Tk
rapidly grew in popularity among academic, engineering, and Unix
programmers. Much like Python itself, Tcl/Tk originated on the Unix
platform and only later migrated to macOS and Windows. Tk's
practical intent and Unix roots still inform its design today, and its
simplicity compared to other toolkits is still a major strength.

Tkinter

is a Python interface to the Tk GUI library and has been a part of the
Python standard library since 1994 with the release of Python version
1.1, making it the de facto GUI library for Python. Documentation for
Tkinter, along with links for further study, can be found in the
standard library documentation at
https://docs.python.org/3/library/tkinter.html

Introducing IDLE

IDLEis an integrated development environment that is bundled with


the Windows and macOS Python distributions (it's readily available in
most Linux distributions as well, usually as IDLE or IDLE3). IDLE is
written in Python using Tkinter, and it provides us with not only an
editing environment for Python, but also a great example of Tkinter in
action. So, while IDLE's rudimentary feature set may not be
considered professional grade by many Python coders, and while
you may already have a preferred environment for writing Python
code, I encourage you to spend some time using IDLE as you go
through this book.
Let's get familiar with IDLE's two primary modes: shellmode and
editormode.
from tkinter import *: This imports the Tkinter library into the global
namespace. This isn't best practice, because it fills your namespace
with a lot of classes, which you might accidentally overwrite, but it's
okay for very small scripts.

from tkinter.ttk import *: This imports the ttk or themed Tk widget


library. We'll be using this library throughout the book, as it adds a
number of useful widgets and improves the look of existing widgets.
Since we're doing the star import here, our Tk widgets will be
replaced by the better-looking ttk widgets wherever applicable (for
instance, our Label object).
root = Tk(): This creates our root or master application object. This
represents the primary top-level window and main execution thread
of the application, so there should be one and only one instance of
Tk for every application.

label = Label(root, text="Hello World”

Creating input field with tkinter/entry widget options and methods

bg - the background color of the widget.


bd - the border width of the widget in pixels.
cursor - the mouse pointer will be changed to the cursor type set
to the narrow, dot, etc.
fg - it represents the color of the text.
font - it represents the font type of the text.

show - it is used to show the entry text of some other type instead
of the string, for example, the password is typed using starts
(*).
textvariable - it is set to the instance of the StringVar to retrieve the
text from the entry.

width - The width of the displayed text or image.

delete(first, last= name) - it is used to delete the specified characters


inside the widget.
get() - it is used to get the text written inside the widget.

activebackground-background color when the button is under the


cursor.
activeforeground - foreground color when the button is under the
cursor.

padx, pady - additional padding of the text. The padx puts some space
between the button widgets and between the
closeButton and the right border of the root
window. The pady puts some space between the
button widgets and the borders of the frame and
the borders of the root window.

Insert(index,5) - it is used to insert the specific string before the


character placed at the specified index.

Label - used to provide a single-line caption for other widgets.

Message - used to display multiline next fields.


it automatically wrap the text.

LabelFrame - a labelframe is a simple container widget.

Creating a Window

import tkinter
Window_Name=tkinter.Tk()
Window_Name.mainloop()
Is a infinite loop used to run application, wait for an event to
occur and process the event as long as the window is not closed.

Windows Attributes

title(text)-used to add title bar


geometry(size, position)
- this method is used for both purpose

resizable (w, h)
-this method is instructs window manager if this window can be
resize or not

Accept Boolean Value

You might also like