fbpx

A Beginner Friendly Way to Spice Up Your Python Code!

分享到 facebook
分享
分享到 linkedin
分享
分享到 twitter
鸣叫
pexels lukas

Learning Python can be a thrilling and gratifying journey. But let’s be honest, sometimes it’s a little disappointing to work on code for hours, only for it to be presented on a bland, black and white terminal screen… So what’s one to do if you want to change things up? Maybe make your code a bit more visual, or interactive even, say with buttons to press. The answer – output to a GUI!

一个 GUI (Graphical User Interface) is a user interface (think screen) that allows people to interact with computers through visual indicators like icons, menus, and windows.

It has perks over the Command Line Interface (CLI), which is more difficult to use and requires users to write commands into computers using only the keyboard and isn’t very interesting. Though, CLI can be handy in its own ways (for prototyping / debugging for example).

So how can you build a GUI in python? There are many libraries that you can use to aid you with this. But one that I recommend for beginners is Tkinter.

Note: Other Python libraries that you can use to create our own GUI applications include: Kivy, Python Qt, wxPython

What is Tkinter?

Tkinter is a built-in Python library for creating graphical user interfaces (no PIP install necessary!). Because It’s easy and basic to use, it’s one of the most often used library for GUI applications in Python. It gives the Tk GUI toolkit an object-oriented interface. 

What are Widgets?

Widgets are GUI elements in Tkinter that allow users to interact with the application using several controls (including Labels, Buttons, ComboBoxes, CheckBoxes, MenuBars, RadioButtons, and many others). 

List of Widgets You Can Use

Here’s a list of things you can add using Tkinter and what they do:

  • Button A clickable button that can interact with code 
  • Canvas It’s used to draw pictures and others layouts like texts, graphics etc. 
  • CheckButton It displays several options to the user as toggle buttons, from which the user can select any number of options. 
  • ComboBox It contains a down arrow to select from a list of available options 
  • Entry It’s used to input single-line text entry from user 
  • Frame It’s used as container to hold and organize the widgets 
  • Label It’s used to display text or image on the screen 
  • Menu It’s used to create all kinds of menus used by an application 
  • Message It works the same as a label and refers to multi-line and non-editable text 
  • RadiButton It’s used to implement one-of-many selection as it allows only one option to be selected 
  • Scale It’s used to provide a graphical slider that allows to select any value from that scale 
  • Scrollbar It’s used to scroll down the contents. It provides a slide controller. 
  • SpinBox It allows users to select from a given set of values 
  • Text It allows users to edit multi-line text and format the way it has to be displayed 

Pretty powerful stuff! I mean, just think of all the things you can do with these basic GUI elements. Not only is this a fun way to play with your code, but it teaches you the basics of GUI development. Later on, this knowledge will come in handy when you want to build something more complex, with say, Kivy.

So what are you waiting for? Dive into the world of GUI building and make your code interactive1 Here’s a good place to start.

But sometimes video courses are not easy to learn from. Things just don’t stick with you like they do when working with a one on one teacher. So why not join our course now and learn GUI and so much more, all from a professional!

 

分享到 facebook
分享
分享到 linkedin
分享
分享到 twitter
鸣叫

相关文章

作者

IMG
汉娜
一个

关于 SCC

让所有学生在科技教育中获得乐趣和进步的重要性是我们的座右铭。我们希望我们的学生不仅为自己,也为社会创造更美好的未来。无论是为自己的电子游戏编程、为自己的卡通动画制作动画,还是构建机器人,我们的导师都可以通过我们的课程指导他们寻找更新的观点并探索未发现的发现。