Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีผูกปุ่ม Shift+Tab ใน Tkinter

Tkinter รองรับการผูกคีย์คอมโบ (key combination) เช่น <Shift-Tab>, <Control-c> เป็นต้น ผ่านเมธอด bind()

ตัวอย่างโค้ด

from tkinter import *
from tkinter import messagebox

win = Tk()
win.geometry("700x350")

def show_msg(e):
    messagebox.showinfo("Message", "Hey There! I hope you are doing well.")

Label(win, text="Admin Has Sent You a Message. Press  to View the Message.",
      font=('Arial 15')).pack(pady=40)

# ผูก Shift+Tab กับฟังก์ชัน show_msg
win.bind('', lambda e: show_msg(e))

win.mainloop()

ผลลัพธ์

กด Shift+Tab จะแสดงกล่องข้อความป๊อปอัป

วิธีผูกปุ่ม Shift+Tab ใน Tkinter