所以我有一个带有画布的 Tkinter 屏幕。我想通过创建一个具有条目小部件的新窗口来更改画布的大小。所以我创建了一个新屏幕并添加了 2 个条目小部件。我想从这些小部件中获取值,并基于此......它应该改变画布的大小。我尝试这样做一个小时,但没有成功。请帮助我。
这是我的代码
from tkinter import *
# create root window
root = Tk()
# Create Canvas
canvas = Canvas(root, width=50, height=50)
# Create an additional window (the one that is used to enter the new geometry)
dialog = Toplevel(root)
# Add entry widgets for width and height to the new window
width_entry = tk.Entry(dialog)
height_entry = tk.Entry(dialog)
# Add a button to the new window that applies the given width and height
apply_button = Button(dialog, text = 'Apply geometry', command = lambda: canvas.geometry(width_entry.get()+'x'+height_entry.get()))
# Its not possible to get the geometry of a canvas in tkinter...so how do I change the size.
# display the entry boxes and button
width_entry.pack()
height_entry.pack()
apply_button.pack()
# start the tk mainloop
root.mainloop()
请帮助我
慕村225694
相关分类