I have always wanted to build Graphical User Interface (GUI) applications but felt that the learning barrier was too high. I read online on forums that you should not use tkinter, because it is ugly and outdated. One day, I had a project where I felt that I really needed to build a GUI so I thought I would try out tkinter, and I was amazed how simple and intuitive the coding was. If you are interested in firing up a GUI fast, below is an explanation of how to do it.
#! python3 import tkinter as tk class Hello_world(tk.Tk): def __init__(self): super().__init__() self.geometry('600x300') if __name__ == "__main__": app = Hello_world() app.title("Hello world from tkinter!") app.mainloop()
First, we import tkinter. Then we define a class that inherits from Tk. We then use the super function that refers to our Tk classes init method and also set the initial size of our frame. In the main loop, we create an instance of our Hello_world class and run it. It is as simple as that. From here you can start to add labels and buttons and all kinds of functionality. If you are interested in learning more about tkinter, there is an ebook available for free on Github written by David Love. Happy coding!
[…] easily! If you want to see how to create an Hello World application in Tkinter, check out my post here. Happy […]
Sweet blog! I found it while browsing on Yahoo News.
Do you have any suggestions on how to get
listed in Yahoo News? I've been trying for a while but I
never seem to get there! Thank you
https://tipsforperfectinterview.com
Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your website?
My website is in the exact same niche as yours and my
visitors would genuinely benefit from some of the information you
present here. Please let me know if this ok with you.
Thank you!