
Lv.1
我是一条没用的小龙~
签名:紫砂中...
在 【Python作品分享】记事本GUI【作品秀】 中回复
我认为你的作品很好,可以改进一下,以下是我自己做的可以借助原生Py编程序的文本编辑工具,你可以在作品中添加像这样的实时编辑工具:
#Easy python
#be made by 昌龙XL
import tkinter as tk
import easygui as g
from tkinter.filedialog import askopenfilename, asksaveasfilename
import os
import subprocess
def run_cmd_Popen_fileno(cmd_string):
"""执行cmd命令"""
os.system(' start cmd.exe /K '+cmd_string)
def open_file():
try:
"""打开"""
filepath = askopenfilename(
filetypes=[("Python Files", "*.py"), ("Text Files", "*.txt")]
)
if not filepath:
return
txt_edit.delete(1.0, tk.END)
with open(filepath, "r") as input_file:
text = input_file.read()
txt_edit.insert(tk.END, text)
window.title(f"Easy Python v1.0.0 - {filepath}")
except:
g.msgbox(msg="文件打开失败",title="Easy python",ok_button="确认")
def save_file():
"""保存"""
filepath = asksaveasfilename(
defaultextension="txt",
filetypes=[("Python Files", "*.py"), ("Text Files", "*.txt")],
)
if not filepath:
return
with open(filepath, "w") as output_file:
text = txt_edit.get(1.0, tk.END)
output_file.write(text)
window.title(f"Easy Python v1.0.0 - {filepath}")
def pip():
a = g.enterbox(msg="输入库的名称",title="Easy Python")
if a == None:
ts = 0
else:
a1 = "pip install "+str(a)
run_cmd_Popen_fileno(a1)
def open_cmd():
"""打开cmd"""
os.system('start cmd.exe')
window = tk.Tk()
window.title("Easy Python v1.0.0 ")
window.rowconfigure(0, minsize=400, weight=1)
window.columnconfigure(1, minsize=400, weight=1)
txt_edit = tk.Text(window)
fr_buttons = tk.Frame(window, relief=tk.RAISED, bd=2)
btn_open = tk.Button(fr_buttons, text="打开", command=open_file)
btn_save = tk.Button(fr_buttons, text="保存", command=save_file)
btn_pip = tk.Button(fr_buttons, text="安装库", command=pip)
btn_cmd = tk.Button(fr_buttons, text="终端", command=open_cmd)
btn_open.grid(row=0, column=0, sticky="ew", padx=5, pady=5)
btn_save.grid(row=1, column=0, sticky="ew", padx=5, pady=5)
btn_pip.grid(row=2, column=0, sticky="ew", padx=5, pady=5)
btn_cmd.grid(row=3, column=0, sticky="ew", padx=5, pady=5)
fr_buttons.grid(row=0, column=0, sticky="ns")
txt_edit.grid(row=0, column=1, sticky="nsew")
window.mainloop()
2023-06-29T14:14:58 点赞:0