оаав ирыыва Asked:2020-03-29 01:15:35 +0000 UTC2020-03-29 01:15:35 +0000 UTC 2020-03-29 01:15:35 +0000 UTC 如何在 tkinter 中找出小部件的长度和高度 772 如何tkinter显示小部件的高度和宽度?有这种可能吗? python 1 个回答 Voted Best Answer Twiss 2020-03-29T01:35:43Z2020-03-29T01:35:43Z .winfo_height()这个(高度)和.winfo_width()(宽度)有一个功能 import tkinter as tk def func(): x = button_place.winfo_width() y = button_place.winfo_height() print(x, y) root = tk.Tk() root.geometry("600x500") button_place = tk.Button(root, text='какой то текст', font='Times 15', command=func) button_place.place(w=400, h=200) root.mainloop() 结论: 400 200 更新 import tkinter as tk class Main(tk.Tk): def __init__(self): super().__init__() self.geometry("800x800") self.button = tk.Button(self, text='какой то текст', font='Times 15') self.button.place(x=8, y=8, w=200, h=100) self.update() self.func() def func(self): x = self.button.winfo_width() y = self.button.winfo_height() but = tk.Button(self, text='еще какой то текст') but.place(x=8 + x, y=8 + y, w=200, h=100) root = Main() root.mainloop()
.winfo_height()这个(高度)和.winfo_width()(宽度)有一个功能结论:
更新