前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python3 TKinter Plac

Python3 TKinter Plac

作者头像
py3study
发布2020-01-06 15:55:37
4180
发布2020-01-06 15:55:37
举报
文章被收录于专栏:python3

Python3 TKinter Place布局 和 各种控件 简单演示

一、说明

1.Tkinter GUI Place布局

2.Button、Label、Menu等各种控件

3.环境:Ubuntu14、Python3.4、Pycharm2018

二、代码

文件名:demo1.py

代码语言:javascript
复制
# -*-coding:utf-8-*-
from tkinter import *


class A:

    def __init__(self, master=None):
        self.root = master
        self.root.geometry('800x600+200+200')
        self.root.title('测试')
        # self.root.bind("<Motion>", self.call_back)
        self.frm1 = Frame(self.root)
        self.frm2 = Frame(self.root)
        self.frm3 = Frame(self.root)
        self.createpage()

    def call_back(self, event):
        print('现在的位置是:', event.x_root, event.y_root)

    def createpage(self):
        menu = Menu(self.root)
        self.root.config(menu=menu)

        filemenu = Menu(menu)
        menu.add_cascade(label='测试1', menu=filemenu)
        filemenu.add_command(label='1')
        filemenu.add_command(label='2')
        filemenu.add_command(label='3')

        onemenu = Menu(menu)
        menu.add_cascade(label='测试2', menu=onemenu)
        onemenu.add_command(label='1')
        onemenu.add_command(label='2')
        onemenu.add_command(label='3')

        self.frm1.config(bg='blue', height=500, width=600)
        Label(self.frm1, text='frm1').place(in_=self.frm1, anchor=NW)
        self.frm1.place(x=180, y=50)

        self.frm2.config(bg='red', height=500, width=150)
        Label(self.frm2, text='frm2').place(anchor=NW)
        self.frm2.place(x=20, y=50)

        self.frm3.config(bg='yellow', height=40, width=760)
        Label(self.frm3, text='frm3').place(in_=self.frm3, anchor=NW)
        self.frm3.place(x=20, y=5)

        # frm3下的Label
        Label(self.frm3, text='Label Test Test',
              fg='red', font='Verdana 10 bold').place(x=300, y=10)
        # frm2下的Button
        for i in range(9):
            Button(self.frm2, text='Button%d' % i).place(x=20, y=20+i*50, width=100)

        # frm1下的控件
        Label(self.frm1, text='项目资源管理平台',
              fg='red', font='Verdana 10 bold').place(x=100, y=50, height=80, width=400)
        Button(self.frm1, text='1', height=1, width=1).place(x=450, y=450)
        Button(self.frm1, text='2', height=1, width=1).place(x=490, y=450)
        Button(self.frm1, text='3', height=1, width=1).place(x=530, y=450)


if __name__ == '__main__':
    root = Tk()
    A(root)
    mainloop()

三、界面效果

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/09/18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Python3 TKinter Place布局 和 各种控件 简单演示
    • 一、说明
      • 二、代码
        • 三、界面效果
        相关产品与服务
        资源编排 TIC
        资源编排 TIC 为您提供易用、高效、安全的基础架构管理平台。平台使用声明型语言,兼容众多优秀的开源社区工具,同时提供代码编辑和视图编辑两种模式,有效降低学习成本和使用难度。TIC 使用代码版本管理的方式管理基础架构,保障基础设施的构建、管理和迁移的可靠性和安全性。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档