trainingwidget.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:PyTouch 作者: mNisblee 项目源码 文件源码
def __init__(self, master):
        super(TrainingWidget, self).__init__(master)

        self.tm = None
        self._tick_id = None

        # text and scrollbar widget
        self._font = font.Font(family='mono', size=-40)

        self._content_frame = Frame(self)
        self._text = Text(self._content_frame, wrap=NONE, exportselection=0, undo=False)
        self._scrollbar = ttk.Scrollbar(self._content_frame, command=self._text.yview)
        # Connect scrollbar and training widget
        self._text['yscrollcommand'] = self._scrollbar.set

        # text tags
        self._text.tag_config('base', font=self._font, spacing1=20, justify=CENTER)
        self._text.tag_config('untyped', foreground='#cccccc')
        self._text.tag_config('hit')
        self._text.tag_config('miss', foreground='#cc0003')
        # text bindings
        self._text.bind('<Configure>', self.on_configure)
        self._text.bind('<FocusOut>', self.on_focus_out)
        self._text.bind('<KeyPress-Escape>', self.on_escape_press)
        self._text.bind('<KeyPress-BackSpace>', self.on_backspace_press)
        self._text.bind('<KeyPress>', self.on_key_press)
        self._text.bind('<Any-Button>', self.on_button)
        self._text.bind('<Motion>', lambda e: 'break')

        # statistics widgets
        self._time_elem = StatsElement(self, 'Elapsed time', ZERO, ZERO)
        self._strokes_elem = StatsElement(self, 'Keystrokes per minute', '0', '0')
        self._accuracy_elem = StatsElement(self, 'Accuracy', '0', '0')
        self._progressbar = ttk.Progressbar(self, orient='horizontal', mode='determinate', value=0)

        # pack and configure master frame
        self._time_elem.grid(column=0, row=0, sticky=N + S + W + E)
        self._strokes_elem.grid(column=1, row=0, sticky=N + S + W + E)
        self._accuracy_elem.grid(column=2, row=0, sticky=N + S + W + E)
        self._progressbar.grid(column=0, row=1, sticky=N + S + W + E, columnspan=3)
        self._content_frame.grid(column=0, row=2, sticky=N + S + W + E, columnspan=3)

        self.columnconfigure(0, weight=1, minsize=self._time_elem.text_width)
        self.columnconfigure(1, weight=1, minsize=self._strokes_elem.text_width)
        self.columnconfigure(2, weight=1, minsize=self._accuracy_elem.text_width)
        self.rowconfigure(2, weight=1)

        # pack and configure text frame
        self._text.grid(column=0, row=0, sticky=N + E + S + W)
        self._scrollbar.grid(column=1, row=0, sticky=N + E + S + W)

        self._content_frame.columnconfigure(0, weight=1, minsize=400)
        self._content_frame.rowconfigure(0, weight=1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号