【问题标题】:Compare screen size with current root window size将屏幕大小与当前根窗口大小进行比较
【发布时间】:2019-10-31 21:23:13
【问题描述】:

我使用 tkinter 创建 GUI。在根窗口内,有一些小部件和一个画布。用户可以控制画布的大小。

我想做什么: 当主根的总大小不适合屏幕时,画布将停止扩展(停止变大)并且可以滚动。

问题: 我不知道如何比较这些值。如何以整数形式获取当前根大小?

这是一个好方法还是有更好的解决方案?

我尝试了什么:

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.

【问题讨论】:

    标签: python tkinter tk


    【解决方案1】:

    您不应该使用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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多