เรียนรู้เขียนโปรแกรม GUI ด้วยภาษา Python และ Tkinter [คอร์สเต็ม]

Posted by


Welcome to our full course on creating a basic GUI program in Python using Tkinter! In this tutorial, we will cover everything you need to know to get started with creating graphical user interfaces in Python.

Tkinter is the standard GUI toolkit for Python and comes pre-installed with Python installations, so you don’t need to install anything extra to get started. It is easy to use and allows you to create simple to complex GUI applications with ease.

Let’s get started by creating a basic GUI program using Tkinter:

Step 1: Import the Tkinter module
To start using Tkinter, you need to import the module into your Python script. You can do this by using the following code:

import tkinter as tk

Step 2: Create a main window
Next, you will need to create the main window of your GUI program. This can be done by creating an instance of the Tk class:

root = tk.Tk()
root.title("My GUI Program")

This code creates a new window with a title "My GUI Program".

Step 3: Add widgets to the window
Now, let’s add some widgets (such as buttons, labels, and text boxes) to our window. Here is an example of adding a label and a button to the window:

label = tk.Label(root, text="Hello, World!")
label.pack()

button = tk.Button(root, text="Click Me")
button.pack()

This code creates a label widget with the text "Hello, World!" and a button widget with the text "Click Me" and adds them to the main window.

Step 4: Run the main event loop
Finally, you will need to run the main event loop of the Tkinter application to start the GUI. This can be done by calling the mainloop method of the root window:

root.mainloop()

This code will start the GUI application and display the main window with the added widgets.

Congratulations! You have created a basic GUI program using Tkinter. You can further customize and enhance your GUI program by adding more widgets, styling them, and adding functionality to them.

In this tutorial, we have covered the basics of creating a GUI program in Python using Tkinter. I hope this tutorial has been helpful in getting you started with creating GUI applications in Python. Happy coding!

0 0 votes
Article Rating
23 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@yongyutkaewkhamhorm7972
1 month ago

แล้วนำไปใช้บนมือถือยังไงครับ

@user-jb9mz6kv6o
1 month ago

ขอบคุณมากๆ ครับพี่ก้อง

@hhhafishifa262
1 month ago

พี่เอาปุ่ม คูณมาจากไหน

@HiperCode10100
1 month ago

พี่ครับ สอนป้องกันการแกะแอพและ bypass หน้าล็อคอินน่อยครับ

@abdulhameedmalik4299
1 month ago

This is a in china language

@chanilsgrarakpor3236
1 month ago

ครบจริงๆช่องนี้
ชอบคับ

@Domecom1
1 month ago

มันลากวัตถุมาใส่เลยเหมือนvb ไม่ได้ ทุก ย่างต้องเขียนเองหมดเลย

@sitthisaklogate6770
1 month ago

ขอบพระคุณอาจารย์มากครับ

@ABsolute23191
1 month ago

ขอบคุณครับสำหรับความรู้

@ackaradechneauthong4495
1 month ago

คลิปเดียว “ รู้เรื่อง “ 👏👏👏

@ConveyorMan
1 month ago

Very good contents.

@mr.everything3598
1 month ago

อยากถามหน่อยครับ พอผมใส่ font ลงไปข้อความมันดันไม่สแดงต้องทำไงครับ

@oooClickLikeooo
1 month ago

Gui มันต้อง run ใน python ก่อนตลอดใข่ไหมครับ เราสามารถ deploy มันบน desktop เพื่อให้ user ใช้ง่ายๆมั้ย

@nopmanop9874
1 month ago

I had no idea tNice tutorials blew up until now holy sNice tutorialt

@keang6256
1 month ago

ขอบคุณมากเลยครับ อาจารย์ทำให้ผมได้เรียนรู้โค้ดเข้าใจขึ้นมากเลยครับ

@user-gs1yp8pu6r
1 month ago

ขอบพระคุณอาจารย์มากๆครับ เข้าใจง่าย เป็นขั้นเป็นตอน ยอดเยี่ยมมากๆครับ

@TomHack555
1 month ago

ขอบคุณครับ

@pisanu6699
1 month ago

เรียนถามครับ ทำไม วิดเก็ต menu ถึงไม่แสดงผลเมนูบน screen ทั้งที่เขียนโค๊ดตามแบบอาจารย์ทุกอย่าง
ใช้เครื่อง mac os x (sierra) ใช้ Python 3..6

@attaponcharoenpon1890
1 month ago

ผมใช้ tkinter มาแสดง opencv ปรากฏว่า พอรันไปนานๆแล้ว app มันจะช้าลงเรื่อยๆ จนถึงเวลาหนึ่งก็จะนิ่งและค้างครับ เคยลองใช้ multiprocessor ดีขึ้นหมายถึง app ยังช้าลงเรื่อยๆ แต่ใช้เวลาที่นานกว่า มีวิธีแก้ไหมครับ

@Alternative_BaconA
1 month ago

Wow pls give me one game mm2 your gui