问题
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)
回答1:
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")
来源:https://stackoverflow.com/questions/63270125/how-do-i-edit-my-code-to-make-the-next-button-lead-to-a-blank-page-in-the-same