# -*- coding: utf-8 -*-
import tkinter as tk

def getNewCreate():
pass

def getCharcount1(sss):
# 添加字数统
status_str_var.set(
'字符数: {count}'.format(count=len(str(text_pad.get('0.0', 'end-1c')).replace(" ", "").replace("\n", ""))))

def JiShiBen():
global Text1, text_pad, count_word, root
root = tk.Tk()
root.title("记事本")
root.geometry("500x800+100+100")

# 添加一级菜单
menu = tk.Menu(root, tearoff=False)

# 添加二级菜单"文件"
fileMenu = tk.Menu(menu, tearoff=False)
fileMenu.add_command(label='新建', command=getNewCreate)
fileMenu.add_command(label='打开')
fileMenu.add_command(label='保存')
fileMenu.add_command(label='另存为')
fileMenu.add_command(label='关闭')

# 将二级菜单添加到一级菜单中
menu.add_cascade(label='文件', menu=fileMenu)

# 添加二级菜单"编辑"
fileMenu1 = tk.Menu(menu, tearoff=False)
fileMenu1.add_command(label='撤销')
fileMenu1.add_command(label='剪切')
fileMenu1.add_command(label='复制')
fileMenu1.add_command(label='粘贴')
fileMenu1.add_command(label='删除')
fileMenu1.add_command(label='查找')
fileMenu1.add_command(label='查找下一个')
fileMenu1.add_command(label='替换')
fileMenu1.add_command(label='转到')
fileMenu1.add_command(label='全选')
fileMenu1.add_command(label='时间/日期')
# 将二级菜单添加到一级菜单中
menu.add_cascade(label='编辑', menu=fileMenu1)

fileMenu3 = tk.Menu(menu, tearoff=False)
fileMenu3.add_command(label='作者:liyuzhoupan')
fileMenu3.add_command(label='版权:20220913')
menu.add_cascade(label='关于', menu=fileMenu3)

# side为位置:
# TOP 这是默认值,由上到下排列
# BOTTOM 由下到上排列
# LEFT 由左到右排列
# RIGHT 由右到左排列

# fill为填充方式:
# tk.X 横向填充,
# tk.Y纵向填充
# tk.BOTH上下左右全部填充

# place绝对位置:
# 横向位置relx=0.7
# 纵向位置rely=0.9

# 添加行数统计
line_var = tk.StringVar()
status_label = tk.Label(root, textvariable=line_var, bd=1, relief=tk.SUNKEN, width=1, anchor=tk.W, bg='#faebd7')
status_label.pack(side=tk.LEFT, fill=tk.Y)

# 添加输入框
text_pad = tk.Text(root, height=30, width=70, font=18)
text_pad.pack(fill=tk.BOTH, expand=True)

# 绑定输入框事件
text_pad.bind(sequence="<Key>", func=getCharcount1)

# 统计字数限制
global status_str_var
status_str_var = tk.StringVar()
status_str_var.set('字符数: {count}'.format(count=len(str(text_pad.get('0.0', 'end-1c')).replace(" ", ""))))
status_label = tk.Label(root, textvariable=status_str_var, bd=1, relief=tk.SUNKEN, anchor=tk.W, font=18)
status_label.pack_forget()
status_label.pack(side=tk.BOTTOM, fill=tk.X)

# 输入框text_pad添加滚动条scroll
scroll = tk.Scrollbar(text_pad)
# scroll绑定输入框text_pad
text_pad.config(yscrollcommand=scroll.set)
# 滚动是触发text_pad变化
scroll.config(command=text_pad.yview)

# 设置放置位置
scroll.pack(side=tk.RIGHT, fill=tk.Y)

# 加载一级菜单到GUI中界面上
root.config(menu=menu)
root.mainloop()

JiShiBen()

最新文章

  1. Web项目使用Oracle.DataAccess.dll 类库连接oracle数据库
  2. webpack入门
  3. wifipineapple使用教程
  4. Safari 前端开发调试 iOS 完美解决方案
  5. css margin collapse
  6. BZOJ 3039: 玉蟾宫( 悬线法 )
  7. 安装Python和pip
  8. 源码安装zabbix_server服务端
  9. python 字符串 string
  10. Linux 命令练习
  11. angularJS的环境搭建--初学
  12. Celery 源码解析五: 远程控制管理
  13. 根据自己的博客数据统计国内IT人群
  14. Redis哨兵机制
  15. 上手d3js
  16. [leetcode]4. Median of Two Sorted Arrays俩有序数组的中位数
  17. 【LeetCode】9. 回文数
  18. Warning: Failed to halt at after bootloader, forced stop at
  19. FTL 数字有逗号
  20. c# txt内存映射技术总结

热门文章

  1. Git分支变基-知识点整理记录
  2. 各种排序算法实现(JAVA)
  3. spring boot swagger ui使用 nginx 部署后无法使用问题
  4. .NET遍历二维数组-先行/先列哪个更快?
  5. 使用Navicat操作MySQL数据库
  6. 视觉十四讲:第六讲_ceres非线性优化
  7. EPICS Archiver Appliance存储waveform记录的尝试
  8. JZOJ 3304. Theresa与数据结构
  9. JZOJ 5346. 【NOIP2017提高A组模拟9.5】NYG的背包
  10. 跳板攻击之:Socks 代理转发