嘉定世外的JinJiayang 2023-01-08 11:09 采纳率: 42.9%
浏览 81

Python tkinter GUI界面带notebook组件的窗口自适应缩放

Python tkinter GUI界面缩放

我正在使用Python自带的图形开发库tkinter(以及ttkbootstrap和mttkinter)进行GUI界面的开发,
在这里面我使用了grid布局、notebook组件以及多重frame嵌套,
如何使窗口自适应缩放比例呢?

img

  • 写回答

2条回答 默认 最新

  • m0_54204465 2023-01-08 11:34
    关注

    使用'stretch'选项来调整窗口的缩放比例。

    'stretch'选项可以设置为'column'、'row'或'both',分别表示对列、行或同时调整缩放比例。

    举个例子:

    如果你希望在垂直方向上调整缩放比例,可以在创建的Frame或Notebook的'top'和'bottom'选项中设置'stretch'选项:

    frame = ttk.Frame(parent, top=10, bottom=10, stretch='row')
    notebook = ttk.Notebook(parent, top=10, bottom=10, stretch='row')
    
    

    如果你希望在水平方向上调整缩放比例,可以在创建的Frame或Notebook的'left'和'right'选项中设置'stretch'选项:

    
    frame = ttk.Frame(parent, left=10, right=10, stretch='column')
    notebook = ttk.Notebook(parent, left=10, right=10, stretch='column')
    

    如果你希望同时调整垂直和水平方向的缩放比例,可以在创建的Frame或Notebook的所有边缘选项(即'top'、'bottom'、'left'和'right')中设置'stretch'选项:

    frame = ttk.Frame(parent, top=10, bottom=10, left=10, right=10, stretch='both')
    notebook = ttk.Notebook(parent, top=10, bottom=10, left=10, right=10, stretch='both')
    
    

    如果你希望使用grid布局的组件也能够缩放,可以在创建的组件的'sticky'选项中设置'stretch'选项:

    label = ttk.Label(parent, text='Label', sticky='ns')
    button = ttk.Button(parent, text='Button', sticky='ns')
    
    

    如果你希望在水平方向上调整缩放比例,可以在创建的组件的'sticky'选项中设置'e'和'w'值:

    label = ttk.Label(parent, text='Label', sticky='ew')
    button = ttk.Button(parent, text='Button', sticky='ew')
    
    

    如果你希望同时调整垂直和水平方向的缩放比例,可以在创建的组件的'sticky'选项中设置'nsew'值:

    
    label = ttk.Label(parent, text='Label', sticky='nsew')
    button = ttk.Button(parent, text='Button', sticky='nsew')
    
    评论

报告相同问题?

问题事件

  • 创建了问题 1月8日

悬赏问题

  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表