Python tkinter+MATLAB入门&实践(6)在界面上添加容器控件,如:frame和panedwindow

在界面上添加容器控件,如:frame和panedwindow

1. 目的

我们有时想把 一个窗口 划分成 几个区域 ,就可以使用这些容器控件,再把label和button等控件放在其上即可。

还可以完成左右、上下expand的功能。

2. frame

frame单独用感觉很诡异,所以在这里就不演示了,代码在这里给出。

想尝试的可以把这个粘贴在代码中尝试看看。

fm_th_left = Frame(thirdwindow,bg="Beige",relief='raised')
fm_th_left.pack(side=LEFT)

fm_th_right = Frame(thirdwindow, bg="HoneyDew", relief='raised')
fm_th_right.pack(side=RIGHT)

3. 程序(third_interface.py)

frame和panedwindow一起使用,可以实现的功能就是我们常见的界面,上中下分开,还可以左右拉伸。

from tkinter import *

def create_2(x):
    # secondwindow.destroy() #第二界面消失!!!尚未解决!!!望指点
    thirdwindow = Tk()  # 第三界面出现,照旧设置。
    thirdwindow.title("软件第三界面")
    thirdwindow.geometry("1000x600")
    thirdwindow.configure(bg="AliceBlue")
    thirdwindow.resizable(False, False)

    #添加panedframe和frame,使得窗口上有三个区域,且能够左右、上下拉伸。
    pw_th = PanedWindow(thirdwindow,orient='vertical',sashrelief='sunken') #(放在哪,其子控件竖直放置[pw_th_top和bottom上下放],分割线样式为sunken)
    pw_th.pack(fill='both', expand=1) #放置,填充整个窗口,可拉伸。
    pw_th_top = PanedWindow(pw_th,orient='horizontal',sashrelief='sunken') #(放pw_th里,其子控件水平放置[fm_th_left和right左右放])
    pw_th_bottom = PanedWindow(pw_th, orient='horizontal', sashrelief='sunken') #(放pw_th里,其子控件水平放置[fm_th_bottom左右放])
    fm_th_left = Frame(pw_th_top,width=200,relief='sunken') #添加左右下3个frame
    fm_th_right = Frame(pw_th_top, height=450, relief='sunken')
    fm_th_bottom = Frame(pw_th_bottom, relief='sunken')
    #将所有的panedframe和frame加到相应项里。
    pw_th.add(pw_th_top),pw_th.add(pw_th_bottom),pw_th_top.add(fm_th_left),pw_th_top.add(fm_th_right),pw_th_bottom.add(fm_th_bottom)

4.将之前的小label放到左边的区域里

就是将(放在哪),由thirdwindow改为fm_th_left,即可。

from tkinter import *

def create_2(x):
    # secondwindow.destroy() #第二界面消失!!!尚未解决!!!望指点
    thirdwindow = Tk()  # 第三界面出现,照旧设置。
    thirdwindow.title("软件第三界面")
    thirdwindow.geometry("1000x600")
    thirdwindow.configure(bg="AliceBlue")
    thirdwindow.resizable(False, False)

    #添加panedframe和frame,使得窗口上有三个区域,且能够左右、上下拉伸。
    pw_th = PanedWindow(thirdwindow,orient='vertical',sashrelief='sunken') #(放在哪,其子控件竖直放置[pw_th_top和bottom上下放],分割线样式为sunken)
    pw_th.pack(fill='both', expand=1) #放置,填充整个窗口,可拉伸。
    pw_th_top = PanedWindow(pw_th,orient='horizontal',sashrelief='sunken') #(放pw_th里,其子控件水平放置[fm_th_left和right左右放])
    pw_th_bottom = PanedWindow(pw_th, orient='horizontal', sashrelief='sunken') #(放pw_th里,其子控件水平放置[fm_th_bottom左右放])
    fm_th_left = Frame(pw_th_top,width=200,relief='sunken') #添加左右下3个frame
    fm_th_right = Frame(pw_th_top, height=450, relief='sunken')
    fm_th_bottom = Frame(pw_th_bottom, relief='sunken')
    #将所有的panedframe和frame加到相应项里。
    pw_th.add(pw_th_top),pw_th.add(pw_th_bottom),pw_th_top.add(fm_th_left),pw_th_top.add(fm_th_right),pw_th_bottom.add(fm_th_bottom)

    # 标签显示该界面是点击了哪个按钮来的(放fm_th_left上)
    if x == 'a':
        la_th_1 = Label(fm_th_left,text="您现在将在爱迪奥特曼\n的指导进行相关操作~",font=('微软雅黑 15 bold'))
        la_th_1.pack(anchor=N)
    elif x == 'b':
        la_th_1 = Label(fm_th_left, text="您现在将在迪迦奥特曼\n的指导进行相关操作~", font=('微软雅黑 15 bold'))
        la_th_1.pack(anchor=N)
    elif x == 'c':
        la_th_1 = Label(fm_th_left, text="您现在将在赛文奥特曼\n的指导进行相关操作~", font=('微软雅黑 15 bold'))
        la_th_1.pack(anchor=N)
    elif x == 'd':
        la_th_1 = Label(fm_th_left, text="您现在将在泰罗奥特曼\n的指导进行相关操作~", font=('微软雅黑 15 bold'))
        la_th_1.pack(anchor=N)

有话说:新人,发布文章是为了记录和学习。有相同需求的可以借鉴学习,有大佬希望指点一二。

Python tkinter +MATLAB 入门学习&实践操作 是一个系列,单个看也成立,一起看更好。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值