zoukankan      html  css  js  c++  java
  • 键盘按键控制程序的简单案例

    # -*- 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()
  • 相关阅读:
    agc027D
    agc027E
    agc036D
    牛客挑战赛43 D-数组操作
    CF587F. Duff is Mad
    CF578F. Mirror Box
    CF708D. Incorrect Flow
    agc022D
    2020.12.16 模拟赛x+1
    Mybatis Plus——[Could not set property 'id' of '***' with value]解决方案
  • 原文地址:https://www.cnblogs.com/czz0508/p/10440396.html
Copyright © 2011-2022 走看看