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


Python Tk.focus方法代码示例

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


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

示例1: __init__

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import focus [as 别名]
class ConfigureGUI:

    def __init__(self):
        #
        # Main application window
        #
        self._root = Tk()
        self._root.title("Othello")
        self._root.focus()
        self._root.minsize(400, 250)
        self._root.columnconfigure(0, weight=1)
        self._root.rowconfigure(1, weight=1)
        
        #
        # Welcome label
        #
        welcome_frame = ttk.Frame(self._root, borderwidth=5)
        welcome_label = ttk.Label(welcome_frame, text="Welcome to GUI Othello!")
        
        welcome_frame.grid(row=0, column=0, sticky="ew")
        welcome_label.grid(row=0, column=0, padx=5, pady=5)
        
        welcome_frame.columnconfigure(0, weight=1)
        
        #
        # Main content (Configuration)
        #
        self._content = ttk.Frame(self._root)
        
        self._row = IntVar()
        row_label = ttk.Label(self._content, text="Number of Rows: ")
        row_picker = ttk.Combobox(self._content, state="readonly", textvariable=self._row, values=[4, 6, 8, 10, 12, 14, 16])
        row_picker.set(8)
        
        self._col = IntVar()
        col_label = ttk.Label(self._content, text="Number of Columns: ")
        col_picker = ttk.Combobox(self._content, state="readonly", textvariable=self._col, values=[4, 6, 8, 10, 12, 14, 16])
        col_picker.set(8)
        
        self._white_starts = BooleanVar()
        white_starts_label = ttk.Label(self._content, text="White starts: ")
        white_starts_picker = ttk.Combobox(self._content, state="readonly", textvariable=self._white_starts, values=[True, False])
        white_starts_picker.current(1)
        
        self._classic_board_str = StringVar()
        classic_board_str_label = ttk.Label(self._content, text="Opening Board Style: ")
        classic_board_str_picker = ttk.Combobox(self._content, state="readonly", textvariable=self._classic_board_str)
        classic_board_str_picker["values"] = ["Classic (white starts in the top left)", "Inverted (black starts in the top left)"]
        classic_board_str_picker.set("Classic (white starts in the top left)")
        
        self._most_wins = BooleanVar()
        most_wins_label = ttk.Label(self._content, text="Most Pieces Wins: ")
        most_wins_picker = ttk.Combobox(self._content, state="readonly", textvariable=self._most_wins, values=[True, False])
        most_wins_picker.current(0)

        self._content.grid(row=1, column=0, sticky="nsew")
        
        row_label.grid(row=0, column=0, sticky=(const.N, const.E), padx=5, pady=2)
        row_picker.grid(row=0, column=1, columnspan=2, sticky=(const.N, const.W, const.E), padx=2, pady=2)
        col_label.grid(row=1, column=0, sticky=(const.N, const.E), padx=5, pady=2)
        col_picker.grid(row=1, column=1, columnspan=2, sticky=(const.N, const.W, const.E), padx=2, pady=2)
        white_starts_label.grid(row=2, column=0, sticky=(const.N, const.E), padx=5, pady=2)
        white_starts_picker.grid(row=2, column=1, columnspan=2, sticky=(const.N, const.W, const.E), padx=2, pady=2)
        classic_board_str_label.grid(row=3, column=0, sticky=(const.N, const.E), padx=5, pady=2)
        classic_board_str_picker.grid(row=3, column=1, columnspan=2, sticky=(const.N, const.W, const.E), padx=2, pady=2)
        most_wins_label.grid(row=4, column=0, sticky=(const.N, const.E), padx=5, pady=2)
        most_wins_picker.grid(row=4, column=1, columnspan=2, sticky=(const.N, const.W, const.E), padx=2, pady=2)
        
        self._content.columnconfigure(0, minsize=70)
        self._content.columnconfigure(1, weight=1, minsize=50)
        self._content.columnconfigure(2, weight=1, minsize=50)
        self._content.rowconfigure(0, weight=1, minsize=30)
        self._content.rowconfigure(1, weight=1, minsize=30)
        self._content.rowconfigure(2, weight=1, minsize=30)
        self._content.rowconfigure(3, weight=1, minsize=30)
        self._content.rowconfigure(4, weight=1, minsize=30)
        
        #
        # Play/Quit buttons frame
        #
        play_frame = ttk.Frame(self._root, borderwidth=5)
        play = ttk.Button(play_frame, text="Play", command=self._press_play)
        cancel = ttk.Button(play_frame, text="Quit", command=exit)
        
        play_frame.grid(row=2, column=0, sticky="nsew")
        play.grid(row=0, column=0, sticky=(const.N, const.S, const.E), padx=5, pady=2)
        cancel.grid(row=0, column=1, sticky=(const.N, const.S, const.W), padx=5, pady=2)
        
        play_frame.columnconfigure(0, weight=1)
        play_frame.columnconfigure(1, weight=1)

    def _press_play(self):
        self._root.destroy()
        self.play = True

    def start(self) -> None:
        self._root.mainloop()
        if not self.play:
            exit()

#.........这里部分代码省略.........
开发者ID:solomc1,项目名称:python,代码行数:103,代码来源:othello_GUI(3).py


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