如何编辑代码以使“下一个”按钮在同一窗口中导致空白页? (不是新窗口) [英] How do I edit my code to make the 'next' button lead to a blank page IN THE SAME WINDOW? (not a new window )
问题描述
from tkinter import Tk, Canvas, Frame, BOTH
from tkinter import *
from tkinter import Tk
#Welcome screen
root = Tk()
root.configure(bg = "steel blue")
canvas = Canvas(root, bg = "steel blue", highlightthickness = 0)
canvas.config(width = 350, height = 250)
#canvas.config(width = root.winfo_screenwidth(), height = root.winfo_screenheight() )
canvas.pack()
#Making of the round rectangle
class Rectangle:
def round_rectangle(x1, y1, x2, y2, radius=25, **kwargs):
points = [x1+radius, y1,
x1+radius, y1,
x2-radius, y1,
x2-radius, y1,
x2, y1,
x2, y1+radius,
x2, y1+radius,
x2, y2-radius,
x2, y2-radius,
x2, y2,
x2-radius, y2,
x2-radius, y2,
x1+radius, y2,
x1+radius, y2,
x1, y2,
x1, y2-radius,
x1, y2-radius,
x1, y1+radius,
x1, y1+radius,
x1, y1]
return canvas.create_polygon(points, **kwargs, smooth=True)
my_rectangle = round_rectangle(10, 60, 330, 250, radius=20, outline = "black", fill="white")
canvas.place(relx=0.5, rely=0.5,anchor=CENTER)
def UserIdentification():
newWindow = Toplevel(root)
Next_button=Button(root,text = "Next", anchor = W, command = UserIdentification)
Next_button.configure(width = 10, bg = "black", fg = "blue" ,borderwidth = 4)
Next_button = canvas.create_window(150, 200, anchor=NW, window=Next_button)
canvas.create_text(170, 100, text = "Hey there, welcome to DeliverToday! \nWe bring your needs right at your doorstep ~ \nhave a great journey ahead!")
root.mainloop()
上面的代码可以完全正常工作,但是我对如何制作下一个感到困惑。按钮创建一个新的空白屏幕(我将在稍后进行设计,但现在将其变为空白,以使其不那么复杂)。我不能使用顶层,因为我不想打开一个新窗口,而是希望它在同一窗口中打开(一个屏幕退出,另一个屏幕打开)。如何使用非常简单的代码来实现? (按钮在画布上)
Hi, so the code above works completely but I am confused on how to make the "Next" button create a new blank screen(which I will design later but blank for now to make it less complicated). I cant use top-level because I don't want a whole new window to open up but I want it to open in the same window (one screen to exit and another to open). How do I do that with a very easy code?? (the button is on a canvas)
推荐答案
您可以使用 delete <删除画布上的所有内容
方法。如果您将其传递给文字字符串 all,
You can delete everything on the canvas with the delete
method. If you pass it the literal string "all" it will delete everything on the canvas.
def UserIdentification():
canvas.delete("all")
这篇关于如何编辑代码以使“下一个”按钮在同一窗口中导致空白页? (不是新窗口)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!