# -*- coding: utf-8 -*- """ Created on Tue Feb 26 12:29:57 2019 @author: 车路历程 """ from tkinter import * def Advance(event): print("前进") def Retreat(event): print("后退") def Left(event): print("向左") def Right(event): print("向右") def stop(evnet): print('停止') # 主函数 def main(): # 使用tkinter.Tk() 生成主窗口 root = Tk() frame = Frame(root, width=100, height=100) frame.bind_all("<Up>", Advance) frame.bind_all("<Down>", Retreat) frame.bind_all("<Left>", Left) frame.bind_all("<Right>", Right) frame.bind_all("<Alt-s>", stop) frame.bind_all("<Alt-S>", stop) frame.pack() var = StringVar() # 生成标签 label = Label(frame, textvariable=var, width=20, height=10) var.set("上下左右键盘控制方向 Alt+s 组合键控制停止") # 将标签添加到主窗口 label.pack() root.title("方向控制器") root.mainloop() main()