簡體   English   中英

如何通過單擊帶有 tkinter 的按鈕打開新的 window?

[英]How do i open a new window on the click of a button with tkinter?

我正在制作一個基於文本的游戲,並且想在單擊一個按鈕的同時關閉原來的一個新的根 window?

#Packages
import tkinter as tk
from tkinter import ttk, BOTTOM
from PIL import ImageTk, Image

#Create Window
root = tk.Tk()
root.geometry("360x740")
root.resizable(True, True)
root.title("Box")
root.configure(bg="black")

#Load Image
canvas = tk.Canvas(root, width=360, height=360, bg="black")
tk.Canvas(bg="black")
canvas.pack()
img = ImageTk.PhotoImage(Image.open("sample_image.jpg"))
canvas.create_image(180, 200, image=img)

#Create Text Widget
T = tk.Text(root, height=10, width=52, bg="black", fg="white")
l = tk.Label(root, text="Hard Living by Amsha", fg="white", bg="black")
l.config(font=(None, 14,))
story = """
"""
l.pack()
T.pack()

#Continue Button
yes_button = ttk.Button(root, text="Continue", command=lambda: next_window())
yes_button.pack(pady=75, side=BOTTOM)

T.insert(tk.END, story)

root.mainloop()

def next_window():
    root.quit()
    root = tk.Tk()
    root.geometry("360x740")
    root.resizable(True, True)
    root.title("Hard Living")
    root.configure(bg="black")

    root.mainloop()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM