在Tkinter上基于键盘显示输出

时间:2018-07-27 13:49:46

标签: python user-interface tkinter

我正在使用opencv和GUI Tkinter开发游戏,我有以下代码

from Tkinter import *
from husky_first import isMatched


class gui:

    def __init__(self,huskyFirst):

        self.husky = huskyFirst

        self.root = Tk()

        self.root.geometry("600x400")
        frame = Frame(self.root)

        frame.pack()

        self.headingLabel = Label(frame,bd=8,relief="solid",font="Times 22 bold",text="The other matching pair is :")
        self.headingLabel.pack()

        self.firstLabel = Label(frame,bd=8,relief="solid",font="Times 20 bold")
        self.firstLabel.pack()

        self.resultLabel = Label(frame,bd=8,relief="solid",font="Times 16 bold")
        self.resultLabel.pack()

        self.clock()
        self.root.mainloop()


    def clock(self):
        matchingPair = self.husky.getMatched()
        self.firstLabel.config(text = str(matchingPair))
        self.root.after(400, self.clock) 

        if self.husky.getIsMatched():
            print('isMatched is true',isMatched)
            self.resultLabel.config(text = "Matched")
            self.husky.setMatched(None)

        elif self.husky.getIsMatched()== False:
            print('isMatched is false',isMatched)
            self.resultLabel.config(text ="No match \n please choose another marker")
            self.husky.setMatched(None)

matchingPair的值存在时,代码自动将输出显示到GUI。我想知道是否有可能在我按下键盘上的字母“ M”以在GUI上显示信息时,如果我没有单击“ M”则什么都不会显示。

0 个答案:

没有答案