Попытка переключения между кадрами в tkinterPython

Программы на Python
Anonymous
Попытка переключения между кадрами в tkinter

Сообщение Anonymous »

Я пытаюсь создать (полу)текстовую игру в tkinter. Я хотел бы иметь возможность переключаться между кадрами, чтобы каждый кадр действовал как меню или карта. Однако каждая кнопка в каждом кадре присутствует с самого начала и переходит, например, от При открытии NewGame кнопки при открытии не исчезают.
import tkinter as tk
from tkinter import *
from tkinter import ttk, simpledialog

LARGE_FONT = "Verdana"

root = tk.Tk()

root.geometry("640x480")

class intothesea(tk.Tk):

def __init__(self, *args, **kwargs):

tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(root, height="640", width="480")

container.pack(side="top", fill="both", expand=True)

container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)

self.frames = {}

for F in (Opening, NewGame, LithHarbor):
frame = F(container, self)

self.frames[F] = frame

frame.grid(row=0, column=0, sticky="nsew")
frame.pack()

self.show_frame(Opening)

def show_frame(self, cont):
tk.Frame.lower(self)
frame = self.frames[cont]
frame.tkraise()

class Opening(tk.Frame):

def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="In. To. The. Sea.", font=LARGE_FONT)
label.pack(pady=10,padx=10)

button = tk.Button(self, text="NEW GAME",
command=lambda: controller.show_frame(NewGame))
button.pack()

button2 = tk.Button(self, text="CONTINUE",
command=lambda: controller.show_frame(LithHarbor))
button2.pack()

class NewGame(tk.Frame):

def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label = tk.Label(root, text="In. To. The. Sea.", font=LARGE_FONT)
label.pack(pady=10,padx=10)

new_character = []

def accept_string():
# Prompt the user to input a string
user_input = simpledialog.askstring("Input", "Enter a string:")

# Print the string to the console
if user_input:
new_character.extend(user_input)
print(user_input)
name.pack_forget()

name = tk.Button(self, text="WHAT IS YOUR NAME?", command=accept_string)
name.pack()

class LithHarbor(tk.Frame):

def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="In. To. The. Sea.", font=LARGE_FONT)
label.pack(pady=10,padx=10)

app = intothesea()
app.mainloop()



Подробнее здесь: https://stackoverflow.com/questions/783 ... in-tkinter

Вернуться в «Python»