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


Python Button.pack_forget方法代码示例

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


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

示例1: __init__

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

#.........这里部分代码省略.........
    # must fix
    def save_pref(self):
        index = 0
        for i in self.valves:
            num = index * 3
            if self.preferences.entry_field[num].get():
                i.set_name(self.preferences.entry_field[num].get())
                self.preferences.entry_field[num].delete(0, 'end')
                
            if self.preferences.entry_field[num + 1].get():
                i.set_action_a(self.preferences.entry_field[num + 1].get())
                self.preferences.entry_field[num + 1].delete(0, 'end')
                
            if self.preferences.entry_field[num + 2].get():
                i.set_action_b(self.preferences.entry_field[num + 2].get())
                self.preferences.entry_field[num + 2].delete(0, 'end')
                
            index += 1
                
    def start_stop(self):
        if self.start_label.get() == 'START':
            self.start_label.set('STOP')
            self.master.update()

            self.run_screen.run_all(True)
            self.home_button.config(state='disabled')
        else:
            self.start_label.set('START')
            self.run_screen.run_all(False)
            self.home_button.config(state='normal')

    def run(self):
        self.summary.grid_remove()
        self.run_button.pack_forget()

        self.run_screen.make_frame()
        self.frame = self.run_screen
        self.frame.grid(row=0, column=0)
        self.header.grid(row=0, column=1)

        self.label.set('RUN')
        self.title.pack(side='top')
        self.start_button.pack()
        self.home_button.pack(side='bottom')

    def to_home(self):
        self.momentary.end_all()
        self.momentary.delete_frame()

        self.lock_button.pack_forget()
        self.run_button.pack_forget()
        self.save_button.pack_forget()
        self.reset_button.pack_forget()
        self.home_button.pack_forget()
        self.start_button.pack_forget()

        self.preferences.grid_remove()
        self.frame.grid_remove()
        self.header.grid_remove()

        self.frame = self.home
        self.frame.grid(row=0, column=0)

    def to_summary(self):
        self.frame.grid_remove()
        self.label.set('SUMMARY')
开发者ID:xistingsherman,项目名称:SPTOR,代码行数:70,代码来源:Gui.py

示例2: __init__

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

    ai = None

    def __init__(self, master):
        # Initial Frame
        self.frame = Frame(master)
        self.frame.pack(fill="both", expand=True)

        # Board canvas
        self.canvas = Canvas(self.frame, width=300, height=300)

        # Symbol selection buttons
        self.x_button = Button(self.frame, text='Play as X', height=4,
                               command=self.set_player_x, bg='white',
                               fg='black')
        self.o_button = Button(self.frame, text='Play as O', height=4,
                               command=self.set_player_o, bg='white',
                               fg='red')

        # Game start button and info box
        self.start_button = Button(self.frame, text="START", height=4,
                                   command=self.start, bg='white', fg='purple')
        self.info_box = Label(self.frame, text='Tic Tac Toe Game', height=4,
                              bg='white', fg='blue')

        self.clean_game_board()

    def start(self):
        """Sets up game board, starts a tic tac toe game,
        and a new AI if one doesn't exist. AI makes first move if
        playing as X
        """
        self.set_game_board()
        self.game = TicTacToe()
        self.game.start()
        if not self.ai:
            self.ai = TicTacToeAI()

        if self.ai_symbol == 'x':
            self.ai_action()

    def _board(self):
        """Draws tic tac toe board"""
        self.canvas.create_rectangle(0, 0, 300, 300, outline="black")
        self.canvas.create_rectangle(100, 300, 200, 0, outline="black")
        self.canvas.create_rectangle(0, 100, 300, 200, outline="black")

    def user_action(self, event):
        """Attempts to take action that matches user click. If the move is valid,
        then calls the AI to make the next move. If not, displays the error.
        """
        move_x = event.x // 100
        move_y = event.y // 100
        move_result = self.game.update(self.player_symbol, (move_x, move_y))
        if move_result == "Success":
            board_x = (200 * move_x + 100) / 2
            board_y = (200 * move_y + 100) / 2
            if self.player_symbol == 'x':
                self.draw_x(board_x, board_y)
            else:
                self.draw_o(board_x, board_y)
            if not self.completed():
                # Wait a bit before calling the ai, for visual style
                self.frame.after(500, self.ai_action)
        else:
            self.info_box['text'] = move_result

    def ai_action(self):
        """Gets the next move from the AI based on current game state,
        and plays.
        """
        state = self.game.get_board()
        move = self.ai.get_move(state)
        move_result = self.game.update(self.ai_symbol, move)
        if move_result == "Success":
            board_x = (200 * move[0] + 100) / 2
            board_y = (200 * move[1] + 100) / 2
            if self.ai_symbol == 'x':
                self.draw_x(board_x, board_y)
            else:
                self.draw_o(board_x, board_y)
            self.completed()

    def completed(self):
        """Checks the game status. If completed, displays the result,
        and asks whether the player would like to start another game.
        """
        status = self.game.done()
        if status == 'e':
            return False
        message = "Click to start a new game."
        if status == 't':
            message = "Tie game. " + message
        else:
            message = "Player " + status.upper() + " has won. " + message
        self.info_box.pack_forget()
        self.start_button.pack(fill="both", expand=True)
        self.start_button["text"] = message
        self.start_button["command"] = self.clean_game_board
#.........这里部分代码省略.........
开发者ID:josopersons,项目名称:tictactoe_ai,代码行数:103,代码来源:tictactoe_gui.py


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