为什么不直接用tkinter模块,还要加上customtkinter模块呢?当然是因为好看啊!python内置的tkinter模块在MacOS系统上的界面还算可以,但是到了Windows系统就会显得很丑,而用customtkinter还能让两个平台之间页面差异看起来不会很大。其实之前用MacOS做过一个用到tkinter中Menu类的记事本,但是我发现菜单类在MacOS和Windows上的用法还有点不一样,总之就是用起来比较难受,所以还是用些customtkinter来优化一下界面,应该可以说是兼容性比较好,customtkinter的控件在Windows和MacOS上的差距不会很大,而tkinter就。。
想要学习customtkinter的可以去github上下载压缩包:https://github.com/TomSchimansky/CustomTkinter
废话少说吧,上代码:
"""
Author: Gooder Chen
Date: 2023.1.17
"""
from customtkinter import *
from tkinter.filedialog import *
from tkinter.messagebox import *
help = """File:
<Control+N> to create a new window;
<Control+O> to open a file;
<Control+S> to save;
<Shift+Control+S> to save as a file;
Edit:
<Control+Z> to undo;
<Shift+Control+Z> to redo;
AUTHOR: Gooder Chen
DATE: 2023/1/19"""
class App(CTk):
def __init__(self):
super().__init__()
# get the const
self.SCREEN_WIDTH = self.winfo_screenwidth()
self.SCREEN_HEIGHT = self.winfo_screenheight()
self.WINDOW_WIDTH = self.SCREEN_WIDTH // 2
self.WINDOW_HEIGHT = self.SCREEN_HEIGHT // 2
# variable
self.current_file = None
self.old_text = None
self.old_text2 = None
# window configure
self.minsize(300, 300)
self.maxsize(self.SCREEN_WIDTH, self.SCREEN_HEIGHT)
self.title("UNKNOWN")
self.center_window()
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1)
# tabview configure
self.tabview = CTkTabview(self,