当前位置: 首页>>代码示例>>Python>>正文


Python Button.invoke方法代码示例

本文整理汇总了Python中tkinter.Button.invoke方法的典型用法代码示例。如果您正苦于以下问题:Python Button.invoke方法的具体用法?Python Button.invoke怎么用?Python Button.invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tkinter.Button的用法示例。


在下文中一共展示了Button.invoke方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_view_text_bind_with_button

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import invoke [as 别名]
    def test_view_text_bind_with_button(self):
        def _command():
            self.called = True
            self.view = tv.view_text(root, 'TITLE_TEXT', 'COMMAND', _utest=True)
        button = Button(root, text='BUTTON', command=_command)
        button.invoke()
        self.addCleanup(button.destroy)

        self.assertEqual(self.called, True)
        self.assertEqual(self.view.title(), 'TITLE_TEXT')
        self.assertEqual(self.view.textView.get('1.0', '1.end'), 'COMMAND')
开发者ID:varunsharma,项目名称:cpython,代码行数:13,代码来源:test_textview.py

示例2: test_view_file_bind_with_button

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import invoke [as 别名]
    def test_view_file_bind_with_button(self):
        def _command():
            self.called = True
            self.view = tv.view_file(root, 'TITLE_FILE', __file__, _utest=True)
        button = Button(root, text='BUTTON', command=_command)
        button.invoke()
        self.addCleanup(button.destroy)

        self.assertEqual(self.called, True)
        self.assertEqual(self.view.title(), 'TITLE_FILE')
        with open(__file__) as f:
            self.assertEqual(self.view.textView.get('1.0', '1.end'),
                             f.readline().strip())
            f.readline()
            self.assertEqual(self.view.textView.get('3.0', '3.end'),
                             f.readline().strip())
开发者ID:varunsharma,项目名称:cpython,代码行数:18,代码来源:test_textview.py

示例3: createWidgets

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import invoke [as 别名]
    def createWidgets(self):
        '''Create and align widgets'''

        top = self.winfo_toplevel()
        top.rowconfigure(0, weight=1)
        top.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1)

        self.passwordout = StringVar()
        self.passwordout.set('- No password generated -')
        self.isnew = IntVar()

        ttitle = Label(self, text=versionStr, font=self.getFont(4))
        wisnew = Checkbutton(self, height=2, font=self.getFont(),
                             text=('This is a new password, that I have not '
                                   'used before'),
                             variable=self.isnew, command=self.toggleCheck)
        tlabel = Label(self, text='Label', font=self.getFont(2))
        tpasswordin1 = Label(self, text='Password', font=self.getFont(2))
        tpasswordin2 = Label(self, text='Password (again)',
                             font=self.getFont(2))
        tlength = Label(self, text='Length', font=self.getFont(2))
        talgorithm = Label(self, text='Algorithm', font=self.getFont(2))
        tsequence = Label(self, text='Sequence #', font=self.getFont(2))
        self.label = ttk.Combobox(self, width=27, font=self.getFont(),
                                  postcommand=self.filterLabels)
        self.passwordin1 = Entry(self, width=27, font=self.getFont(), show="*")
        self.passwordin2 = Entry(self, width=27, font=self.getFont(), show="*",
                                 state=DISABLED)
        length = Spinbox(self, width=3, font=self.getFont, from_=9,
                         to=171, textvariable=self.lengthVar)
        self.algorithm = ttk.Combobox(self, width=27, font=self.getFont(),
                                      values=algos.algorithms)
        sequence = Spinbox(self, width=3, font=self.getFont, from_=1,
                           to=sys.maxsize, textvariable=self.sequenceVar)
        genbutton = Button(self, text="Generate password",
                           font=self.getFont(), command=self.validateAndShow,
                           default="active")
        clrbutton = Button(self, text="Clear fields", font=self.getFont(),
                           command=self.clearIO)
        self.result = Entry(self, font=self.getFont(4),
                            textvariable=self.passwordout, state="readonly",
                            fg="black", readonlybackground="gray")

        # Keybindings
        self.passwordin1.bind('<Return>', lambda e: genbutton.invoke())
        self.passwordin2.bind('<Return>', lambda e: genbutton.invoke())
        length.bind('<Return>', lambda e: genbutton.invoke())
        self.algorithm.bind('<Return>', lambda e: genbutton.invoke())
        sequence.bind('<Return>', lambda e: genbutton.invoke())
        self.master.bind('<Control-q>', lambda e: self.quit())
        self.master.bind('<Escape>', lambda e: self.reset())
        self.label.bind('<<ComboboxSelected>>', self.labelSelected)
        self.label.bind('<FocusOut>', self.labelFocusOut)

        # Layout widgets in a grid
        ttitle.grid(row=0, column=0, sticky=N + S + E + W, columnspan=2)
        wisnew.grid(row=1, column=0, sticky=N + S + E + W, columnspan=2)

        tlabel.grid(row=2, column=0, sticky=N + S + W)
        self.label.grid(row=2, column=1, sticky=N + S + E + W)

        tpasswordin1.grid(row=3, column=0, sticky=N + S + W)
        self.passwordin1.grid(row=3, column=1, sticky=N + S + E + W)

        tpasswordin2.grid(row=4, column=0, sticky=N + S + W)
        self.passwordin2.grid(row=4, column=1, sticky=N + S + E + W)

        tlength.grid(row=5, column=0, sticky=N + S + W)
        length.grid(row=5, column=1, sticky=N + S + E + W)

        talgorithm.grid(row=6, column=0, sticky=N + S + W)
        self.algorithm.grid(row=6, column=1, sticky=N + S + E + W)

        tsequence.grid(row=7, column=0, sticky=N + S + W)
        sequence.grid(row=7, column=1, sticky=N + S + E + W)

        clrbutton.grid(row=8, column=0, sticky=N + S + E + W, columnspan=2)
        genbutton.grid(row=9, column=0, sticky=N + S + E + W, columnspan=2)
        self.result.grid(row=10, column=0, sticky=N + S + E + W, columnspan=2)

        # Initial values
        self.algorithm.set(self.settings.algorithm)

        # Initially, set focus on self.label
        self.label.focus_set()
开发者ID:babab,项目名称:DisPass,代码行数:89,代码来源:gui.py

示例4: TimerFrame

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import invoke [as 别名]

#.........这里部分代码省略.........
            self.reset_timer_btn
        ))

        self.refresh_section()

    def _update_current_time(self):
        """
        Update the timer of current time and set the timing for next second.
        """
        self.current_time_lbl.configure(text=time.strftime('%H:%M:%S'))
        self.master.after(1000, self._update_current_time)

    def _invert_ui(self):
        """
        Invert colors in the GUI including font colors and backgrounds.
        """
        self.ui_colors.reverse()
        bg, fg = self.ui_colors
        self.master.configure(bg=bg)
        self.configure(bg=bg)
        for part in self.inverting_parts:
            part['background'] = bg
            part['foreground'] = fg

    def start_timer(self):
        """
        Start the main timer and timer updating.
        """
        self.timer_control_btn.configure(text='STOP!', command=self.stop_timer)
        self.timer_id = self.master.after(1000, self.update_timer)

    def update_timer(self):
        """
        Update the timer time and check the next section.
        """
        self.section_remaining -= timedelta(seconds=1)

        if self.section_remaining.total_seconds() == 0:
            self.actual_section += 1
            self._invert_ui()
        elif self.section_remaining.total_seconds() < 5:
            self._invert_ui()

        self.remaining_time_lbl.configure(text=format_delta(self.section_remaining))
        self.elapsed_time_lbl.configure(
            text=format_delta(EXAM_SECTIONS[self.actual_section][1] - self.section_remaining)
        )
        if self.section_remaining.total_seconds() > 0:
            self.timer_id = self.master.after(1000, self.update_timer)

    def stop_timer(self):
        """
        Stop the main timer.
        """
        if self.timer_id:
            self.master.after_cancel(self.timer_id)
        self.timer_control_btn.configure(text='START!', command=self.start_timer)

    def reset_timer(self):
        """
        Ask for resetting the main timer and may reset the main timer.
        :return:
        """
        if askyesno('Jste si jisti?', 'Opravdu chcete zastavit a vynulovat čítání?', default=NO):
            self.stop_timer()
            self.actual_section = 0

    @property
    def actual_section(self):
        """
        Return actual section index.
        """
        return self._actual_section

    @actual_section.setter
    def actual_section(self, new):
        """
        Set the new section index and refresh section state.
        """
        self._actual_section = new
        self.refresh_section()

    def refresh_section(self):
        """
        Refresh labels and main timer state.
        """
        section_title, section_length = EXAM_SECTIONS[self.actual_section]
        self.section_title_lbl.configure(text=section_title)
        self.section_remaining = copy(section_length)
        self.remaining_time_lbl.configure(text=format_delta(self.section_remaining))
        self.elapsed_time_lbl.configure(
            text=format_delta(EXAM_SECTIONS[self.actual_section][1] - self.section_remaining)
        )

    def bind_keyboard(self):
        """
        Bind shortcuts to the keyboard.
        """
        self.master.bind('<space>', lambda *args, **kwargs: self.timer_control_btn.invoke())
        self.master.bind('<Delete>', lambda *args, **kwargs: self.reset_timer_btn.invoke())
开发者ID:spseol,项目名称:umz-timer,代码行数:104,代码来源:main.py


注:本文中的tkinter.Button.invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。