我对 Tkinter 还很陌生,我正在尝试制作一个登录屏幕。功能是存在的,但是我希望我的画布是 200x300px,但这似乎不起作用。它返回给我一个画布,刚好适合按钮和输入字段。请帮忙!import tkinter as tkclass Login_Screen:def __init__(self, master): self.master = master self.canvas = tk.Canvas(self.master, width=200, height=300) self.frame = tk.Frame(self.canvas) self.input_user_log = tk.Entry(self.frame) self.button1 = tk.Button(self.frame, text="Log in", width=15, command=self.return_login_info) self.input_user_log.pack() self.canvas.pack() self.button1.pack() self.frame.pack()def return_login_info(self): print(self.input_user_log.get())root = tk.Tk()app = Login_Screen(root)root.mainloop()
1 回答
一只甜甜圈
TA贡献1836条经验 获得超5个赞
使用geometry()
上的方法master
。
import tkinter as tkclass Login_Screen: def __init__(self, master): self.master = master self.master.geometry("300x200") self.canvas = tk.Canvas(self.master) self.frame = tk.Frame(self.canvas) self.input_user_log = tk.Entry(self.frame) self.button1 = tk.Button(self.frame, text="Log in", width=15, command=self.return_login_info) self.input_user_log.pack() self.canvas.pack() self.button1.pack() self.frame.pack()
添加回答
举报
0/150
提交
取消