24
Learning Python- Intermediate course: Day 17, Tkinter β a fast and easy way to create GUI applications.
Python has a inbuilt package for GUI handling known as 'Tkinter'. This GUI toolkit is available on most Unix platforms, including macOS, as well as on Windows systems.
Note- Tkinter provides a powerful object-oriented interface to the Tk-GUI toolkit. GUI requires a lot of OOP stuff. OOP python is still not covered in this course, and would be subsequently covered after GUI is completed. So till that time, don't worry if OOP things are not 100% clear. While learning GUI it is important to understand how to design things rather than how they are implemented by python. Learning OOP concepts will throw light upon how they are implemented and things will start getting clearer and clearer.
But what is Tkinter?
The Tkinter package is actually an interface to the GUI toolkit, called as Tk-GUI. However, Tkinter is not the only GUI Programming toolkit for Python. It is one of the most common and easy to learn interface. It is the only framework thatβs built into the Python standard library. Other notable interfaces are wxPython and JPython (Jython. wxPython is an open-source Python interface for wxWindows, while JPython is a Python port for Java. JPython boasts of giving Python scripts a seamless access to Java class libraries on the local machine. Other alternatives include- PyQt, PySide, Pygame, Pyglet, and PyGTK. You can check them out at the wiki links provided.
The name Tkinter comes from Tk interface. Tkinter was written by Fredrik Lundh. It is free software released under a Python license.
Advantages of Tkinter
Disadvantage of Tkinter
This is why Tkinter is ideal for just studying and exploring GUI in Python.
Didn't work for you? Well it didn't work for me either.
C:\Users\aatma>python -m tkinter
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
In my device, the
py
keyword opens python, so typing in py -m tkinter
worked for me.Common mistake-- We need to type this in the command prompt, and not the python command line!
This won't work-
C:\Users\aatma>py
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> python -m tkinter
File "<stdin>", line 1
python -m tkinter
^
SyntaxError: invalid syntax
That's all for this part. Excited? Before you even realize, we will be making applications much more powerful and exciting than this one. So stay tuned for the next parts of the Learning Python Course.
π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯
Follow me on GitHub for updates.......
Follow me on GitHub for updates.......
24