Python tkinter 의 Bind(귀속 이벤트)사용 예시
# -*- encoding=utf-8 -*-
import tkinter
from tkinter import *
def left_mouse_down(event):
  print('      ')
  #      
  widget = event.widget
  print('       :{}'.format(widget))
  print('    :{}'.format(widget.cget('bg')))
  widget_x = event.x #          x
  print('         :{}'.format(widget_x))
  widget_y = event.y #          y
  print('         :{}'.format(widget_y))
  x_root = event.x_root #              
  print('             :{}'.format(x_root))
  y_root = event.y_root #              
  print('             :{}'.format(y_root))
def left_mouse_up(event):
  print('      ')
def moving_mouse(event):
  print('         ')
def moving_into(event):
  print('    ')
def moving_out(event):
  print('    ')
def right_mouse_down(event):
  print('      ')
def right_mouse_up(event):
  print('      ')
def pulley_up(event):
  print('      ')
def focus(event):
  print('    ')
def unfocus(event):
  print('    ')
if __name__ == '__main__':
  win = tkinter.Tk() #   
  win.title('     ') #   
  screenwidth = win.winfo_screenwidth() #     
  screenheight = win.winfo_screenheight() #     
  width = 500
  height = 300
  x = int((screenwidth - width) / 2)
  y = int((screenheight - height) / 2)
  win.geometry('{}x{}+{}+{}'.format(width, height, x, y)) #       
  label = Label(text='  ', relief='g', font=('  ', 20))
  label.pack(pady=10)
  label.bind('<Button-1>', left_mouse_down) #       
  label.bind('<ButtonRelease-1>', left_mouse_up) #       
  label.bind('<Button-3>', right_mouse_down) #       
  label.bind('<ButtonRelease-3>', right_mouse_up) #       
  label.bind('<B1-Motion>', moving_mouse) #          
  label.bind('<Enter>', moving_into) #       
  label.bind('<Leave>', moving_out) #       
  label.bind('<FocusIn>', focus) #     
  label.bind('<FocusOut>', unfocus) #     
  label.focus_set() #     
  Entry().pack()
  win.mainloop() 
 2、키보드 이벤트 귀속 및 이벤트 속성 획득
# -*- encoding=utf-8 -*-
import tkinter
from tkinter import *
def keyboard_event(event):
  char = event.char
  print('   char:{}'.format(char))
  key_code = event.keycode
  print('   key code:{}'.format(key_code))
def entry_enter(event):
  print('      :' + entry.get())
def shift_f(event):
  print('SHIFT + F')
  print(event.char)
  print(event.keycode)
def num_lock(event):
  print('num_lock')
  print(event.char)
  print(event.keycode)
if __name__ == '__main__':
  win = tkinter.Tk() #   
  win.title('     ') #   
  screenwidth = win.winfo_screenwidth() #     
  screenheight = win.winfo_screenheight() #     
  width = 500
  height = 300
  x = int((screenwidth - width) / 2)
  y = int((screenheight - height) / 2)
  win.geometry('{}x{}+{}+{}'.format(width, height, x, y)) #       
  label = Label(text='  ', relief='g', font=('  ', 20))
  label.pack(pady=10)
  label.focus_set()
  label.bind('<Return>', keyboard_event) #     
  label.bind('<Shift F>', shift_f)
  label.bind('<Num_Lock>', num_lock)
  entry = Entry()
  entry.pack()
  entry.bind('<Return>', entry_enter) #     
  win.mainloop() 
 이상 은 Python tkinter 의 Bind(바 인 딩 이벤트)의 사용 예제 에 대한 상세 한 내용 입 니 다.python tkinter Bind(바 인 딩 이벤트)에 관 한 자 료 는 다른 관련 글 을 주목 하 십시오!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
로마 숫자를 정수로 또는 그 반대로 변환그 중 하나는 로마 숫자를 정수로 변환하는 함수를 만드는 것이었고 두 번째는 그 반대를 수행하는 함수를 만드는 것이었습니다. 문자만 포함합니다'I', 'V', 'X', 'L', 'C', 'D', 'M' ; 문자열이 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.