Python可视化Tkinter进阶grid布局详情

目录

1、grid布局

  • Tkinter提供了两中布局方式
  • pack只能逐行添加
  • grid可以自定义布局

1.1、pack布局

Python可视化Tkinter进阶grid布局详情

1.2、grid布局

grid是python标准库提供的控件布局工具

Python可视化Tkinter进阶grid布局详情

  • column : 设置控件对象显示的列(从0开始)
  • row :设置控件对象显示的行(从0开始)
  • ipadx :设置控件对象左右内边距
  • ipady : 设置控件对象上下内边距
  • padx :设置控件对象左右外边距
  • pady : 设置控件对象上下外边距
  • columnspan :设置控件对象所占列数
  • rowspan : 设置控件对象所占行数

2、简易Base64装换工具制作

2.1、源码分析

# coding:utf-8
import tkinter as tk
import base64
import tkinter.messagebox as tm

# 定义Base64加密函数函数
def get_encode():
get_var = te1.get(\"1.0\", \"end\")
en_str = base64.b64encode(get_var.encode(\"gbk\"))
en_result = en_str.decode(\"gbk\")
tt1.delete(\"1.0\", \"end\")
var2.set(\"加密结果为:\")
tt1.insert(\"insert\", en_result)
# 定义Base64解密函数函数
def get_decode():
get_var = bytes(te1.get(\"1.0\", \"end\"), encoding=\"gbk\")
en_str = base64.b64decode(get_var)
en_result = en_str.decode(\"gbk\")
tt1.delete(\"1.0\", \"end\")
var2.set(\"解密结果为:\")
tt1.insert(\"insert\", en_result)
def menuCommand():
tm.showinfo(\"\", \"功能暂未开放\")
def add_menu(name):
main_menu.add_command(label=f\"{name}\", command=menuCommand)
window = tk.Tk()
width = 1100
height = 650
window_width = int((window.winfo_screenwidth()-width)/2)
window_height = int((window.winfo_screenheight()-height)/2)
window.title(\"Base64转换工具\")
window.geometry(f\"{width}x{height}+{window_width}+{window_height}\")
window.resizable(0, 0)
# window.iconbitmap(r\"favicon.ico\")
lb1 = tk.Label(window, text=\"欢迎使用Base64转换工具\", font=(\"宋体\", 14), width=110, height=2, relief=\"groove\",
anchor=\"center\", bg=\"#FDF5E6\")
lb2 = tk.Label(window, text=\"请在下面输入要加密或者解密的内容:\", font=(\"宋体\", 14), width=110, height=2, relief=\"groove\",
anchor=\"w\")
te1 = tk.Text(window, width=100, height=10, bg=\"#FDF5E6\", font=(\"宋体\", 14, \'bold\'))
# 调用Base64加密函数函数
bt1 = tk.Button(window, text=\"Base64加密\", font=(\"宋体\", 14), width=10, height=1, relief=\"raised\",
command=get_encode, anchor=\"e\")
# 调用Base64解密函数函数
bt2 = tk.
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容