Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Tkinter에서 shift+tab에 바인딩하는 방법은 무엇입니까?

<시간/>

Tkinter 이벤트는 특정 작업이나 작업을 수행해야 하는 모든 응용 프로그램에 매우 유용합니다. Tkinter에서 이벤트는 일반적으로 특정 이벤트에 대한 코드와 논리를 포함하는 함수를 정의하여 생성됩니다. 이벤트를 호출하기 위해 일반적으로 일부 키 또는 버튼 위젯으로 이벤트를 바인딩합니다. bind 함수는 두 개의 매개변수를 취합니다. ('', callback) 버튼이 이벤트를 트리거할 수 있도록 합니다.

다음 예에서 동일한 접근 방식을 사용하여 키 조합을 눌러 팝업 메시지를 트리거합니다. .

예시

# Import the required libraries
from tkinter import *
from tkinter import messagebox

# Create an instance of tkinter frame
win= Tk()

# Set the size of the tkinter window
win.geometry("700x350")

# Define a function to show the popup message
def show_msg(e):
   messagebox.showinfo("Message","Hey There! I hope you are doing well.")

# Add an optional Label widget
Label(win, text = "Admin Has Sent You a Message. " "Press <Shift+Tab> to View the Message.", font = ('Aerial 15')).pack(pady= 40)

# Bind the Shift+Tab key with the event
win.bind('<Shift-Tab>', lambda e: show_msg(e))
win.mainloop()

출력

위의 프로그램을 실행하면 레이블 위젯이 포함된 창이 표시됩니다. 키 조합을 누르면 화면에 메시지가 팝업됩니다.

Tkinter에서 shift+tab에 바인딩하는 방법은 무엇입니까?