【发布时间】:2021-11-02 09:00:10
【问题描述】:
from pathlib import Path
import tkinter as tk
class SampleApp(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self._frame = None
self.switch_frame(StartPage)
def switch_frame(self, frame_class):
"""Destroys current frame and replaces it with a new one."""
new_frame = frame_class(self)
if self._frame is not None:
self._frame.destroy()
self._frame = new_frame
self._frame.place()
class StartPage(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
OUTPUT_PATH = Path(__file__).parent
ASSETS_PATH = OUTPUT_PATH / Path("MENUASSETS")
def relative_to_assets(path: str, ) -> Path:
return ASSETS_PATH / Path(path)
canvas = tk.Canvas(self,bg="#F7F7F7",height=470,width=600,bd=0,highlightthickness=0,relief="ridge")
canvas.place(x=0, y=0)
canvas.create_rectangle(0.0,0.0,396.0,470.0,fill="#000000",outline="")
self.button_image_1 = tk.PhotoImage(file=relative_to_assets("button_admin.png"))
button_1 = tk.Button(self,image=self.button_image_1,borderwidth=0,highlightthickness=0,command=lambda: master.show_frame(userinterface),relief="flat")
button_1.place(x=70.0,y=66.0,width=256.0,height=74.0)
self.button_image_2 = tk.PhotoImage(file=relative_to_assets("button_user.png"))
button_2 = tk.Button(self,image=self.button_image_2,borderwidth=0,highlightthickness=0,command=lambda: print("button_2 clicked"), relief="flat")
button_2.place(x=75.0,y=198.0,width=256.0,height=74.0)
self.button_image_3 = tk.PhotoImage(file=relative_to_assets("button_vc.png"))
button_3 = tk.Button(self,image=self.button_image_3,borderwidth=0,highlightthickness=0,command=lambda: print("button_3 clicked"),relief="flat")
button_3.place(x=70.0,y=330.0,width=256.0,height=74.0)
self.button_image_4 = tk.PhotoImage(file=relative_to_assets("button_mexit.png"))
button_4 = tk.Button(self,image=self.button_image_4,borderwidth=0,highlightthickness=0,command=lambda: print("button_4 clicked"),relief="flat")
button_4.place(x=462.0,y=415.0,width=77.0,height=36.0)
canvas.create_text(self,13.0,424.0,anchor="nw",text="MAYA",fill="#000000",font=("Sora Regular", 27 * -1))
self.image_image_1 = tk.PhotoImage(file=relative_to_assets("logo.png"))
self.image1 = canvas.create_image(self,500.0,145.0,image=self.image_image_1)
错误:
_tkinter.TclError: bad screen distance ".!startpage"
【问题讨论】:
-
提供minimal reproducible example和完整的错误回溯(从单词“Traceback”开始),我也建议不要使用
.place,使用.pack或.grid(可以混用)在单独的容器中) -
谢谢!建议!
-
请修剪您的代码,以便更容易找到您的问题。请按照以下指南创建minimal reproducible example。