将屏幕尺寸与当前根 window 尺寸进行比较
Compare screen size with current root window size
我使用 tkinter 创建一个 GUI。在根 window 中,有一些小部件和一个 canvas。用户可以控制 canvas.
的大小
我想做的事情:
当主根的总大小不适合屏幕时,canvas 将停止扩展(停止变大)并且可以滚动。
问题:
我不知道如何比较这些值。如何获取当前根大小的整数?
这是一个好的方法还是有更好的解决方案?
我尝试了什么:
root.winfo_screenwidth() and root.winfo_screenheight() #to get Screen size.
root.winfo_geometry() or root.geometry() #to get the current size of the root as a string in %sx%s+0+0 format.
你不应该使用 root.geometry()
来解决这个问题。试试 root.winfo_width()
和 root.winfo_height()
代替:
# the code before checking size
if root.winfo_width() * root.winfo_height() < root.winfo_screenwidth() * root.winfo_screenheight():
# the code to do when the main root doesn't fit in the Screen
# the code after checking size
我使用 tkinter 创建一个 GUI。在根 window 中,有一些小部件和一个 canvas。用户可以控制 canvas.
的大小我想做的事情: 当主根的总大小不适合屏幕时,canvas 将停止扩展(停止变大)并且可以滚动。
问题: 我不知道如何比较这些值。如何获取当前根大小的整数?
这是一个好的方法还是有更好的解决方案?
我尝试了什么:
root.winfo_screenwidth() and root.winfo_screenheight() #to get Screen size.
root.winfo_geometry() or root.geometry() #to get the current size of the root as a string in %sx%s+0+0 format.
你不应该使用 root.geometry()
来解决这个问题。试试 root.winfo_width()
和 root.winfo_height()
代替:
# the code before checking size
if root.winfo_width() * root.winfo_height() < root.winfo_screenwidth() * root.winfo_screenheight():
# the code to do when the main root doesn't fit in the Screen
# the code after checking size