zoukankan      html  css  js  c++  java
  • Python3 tkinter 对话框简单布局

     1 from tkinter import *
     2 import tkinter.messagebox
     3 import datetime
     4 import time
     5 tk =Tk()
     6 tk.geometry('800x600')#窗体大小
     7 tk.resizable(False, False)#固定窗体
     8 
     9 #界面布局
    10 #左侧上方Frame
    11 frmLt=Frame(tk,width=400,height=200,bg='white')
    12 frmLt.grid(row=0,column=0,padx=5,pady=5)
    13 
    14 #左侧底部Frame
    15 frmLb=Frame(tk,width=400,height=200,bg='red')
    16 frmLb.grid(row=1,column=0,padx=5,pady=5)
    17 
    18 #右侧放logo的Frame,sticky=N用于定位N+W+E+S
    19 frmRt=Frame(tk,width=200,height=200)
    20 frmRt.grid(row=0,rowspan=2,column=1,sticky=N)
    21 
    22 #最底部按钮Frame
    23 frmBt=Frame(tk,width=200,height=30)
    24 frmBt.grid(row=2,column=0,columnspan=2,sticky=W)#sticky=W控制容器中内容靠左侧
    25 
    26 #Logo
    27 image=PhotoImage(file='1.png')
    28 lblImage=Label(frmRt,image=image)
    29 lblImage.grid()
    30 
    31 #上方输入文本框
    32 text_top=Text(frmLt,width=56)
    33 text_top.insert(INSERT,'开始聊天吧...')
    34 #print(text_top.get(1.2,2.15))#文本行下标.列下标,  行下标.列下表进行索引查找
    35 #print(text_top.get(0.0,END))#获取所有文本
    36 text_top.grid(row=0,column=0)
    37 text_top.tag_config('B',foreground='red')#定义两个tag_config 起名字为B,用于设置字体颜色,在inert时候指定这个配置
    38 text_top.tag_config('A',foreground='blue')
    39 
    40 #下方输入文本框
    41 text_bottom=Text(frmLb,width=56,bg='red')
    42 text_bottom.grid(row=0,column=0)
    43 
    44 #发送信息
    45 def send():
    46     msg=text_bottom.get(0.0,END)
    47     #r=str('{0}[time:{1}]
    '.format(msg,datetime.datetime.now()))
    48     text_top.insert('0.0', str(datetime.datetime.now())+'
    ', 'B') #0.0即行索引.列索引
    49     text_top.insert('0.0', msg, 'A')
    50     text_bottom.delete(0.0,END) #清空文本框内容;END表示下标,即文本最后一个位置
    51     #tkinter.messagebox.showinfo('提示','人生苦短') #showwaring...
    52     #a = tkinter.messagebox.askokcancel('提示', '要执行此操作吗')
    53     #print(a)
    54 
    55 btn_1=Button(frmBt,text='发送',command=send)#绑定触发的方法send方法
    56 btn_1.grid(row=0,column=0)
    57 btn_2=Button(frmBt,text="取消" )
    58 btn_2.grid(row=0,column=1)
    59 
    60 #Frame大小固定不动
    61 frmRt.grid_propagate(0) 
    62 frmLb.grid_propagate(0)
    63 frmLt.grid_propagate(0)
    64 frmBt.grid_propagate(0)
    65 
    66 mainloop()

    效果如下:

  • 相关阅读:
    变量提升
    前端UI框架和JS类库
    ES6---Map数据结构
    ES6---Set数据结构
    Array.from//Array.of的用法
    闭包的理解和应用场景
    vue-router 的用法
    原型链和作用域链的理解
    WordPress更换了域名 主页、文章、图片路径错误 解决办法
    wordpress 安装新的主题后启动后报错
  • 原文地址:https://www.cnblogs.com/ygzhaof/p/9712684.html
Copyright © 2011-2022 走看看