การใช้งาน Python GUI (Tkinter) : Adding a Dialog (การเพิ่มไดอะล็อก)

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: การใช้งาน Python GUI (Tkinter) : Adding a Dialog (การเพิ่มไดอะล็อก)

การใช้งาน Python GUI (Tkinter) : Adding a Dialog (การเพิ่มไดอะล็อก)

โดย Jom07 » 08/02/2018 1:50 pm

Adding a Dialog เป็นการสร้างกล่องโต้ตอบแสดงข้อความรอให้ผู้ใช้ปิดกล่องโต้ตอบ
ตัวอย่าง

โค้ด: เลือกทั้งหมด

from tkinter import *

class MyDialog:

    def __init__(self, parent):

        top = self.top = Toplevel(parent)

        Label(top, text="Value").pack()

        self.e = Entry(top)
        self.e.pack(padx=5)

        b = Button(top, text="OK", command=self.ok)
        b.pack(pady=5)

    def ok(self):p

        print ("value is", self.e.get)

        self.top.destroy()


root = Tk()
Button(root, text="Hello!").pack()
root.update()

d = MyDialog(root)

root.wait_window(d.top)
ผลรัน

รูปภาพ


ศึกษาจาก : Exploring Python

ข้างบน