#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tkinter import *
import hashlib
import time
LOG_LINE_NUM = 0
class MY_GUI():
def __init__(self,init_window_name):
self.init_window_name = init_window_name
#设置窗口
def set_init_window(self):
self.init_window_name.title("创建文本文档_v1.2") #窗口名
self.init_window_name.geometry('500x200+100+100') #1086*681为窗口大小,+100 +100 定义窗口弹出时的默认展示位置
self.init_window_name["bg"] = "gray" #窗口背景色,其他背景色见:blog.csdn.net/chl0000/article/details/7657887
#self.init_window_name.attributes("-alpha",0.9) #虚化,值越小虚化程度越高
#标签
self.init_data_label = Label(self.init_window_name, text="创建路径")
self.init_data_label.grid(row=0, column=0)
self.name_data_label = Label(self.init_window_name, text="文件名称")
self.name_data_label.grid(row=3, column=0)
self.result_data_label = Label(self.init_window_name, text="文本内容")
self.result_data_label.grid(row=5, column=0)
#文本框
self.init_data_Text = Text(self.init_window_name, width=50, height=1) #输入路径名称
self.init_data_Text.grid(row=0, column=1, rowspan=1, columnspan=20)
self.name_data_Text = Text(self.init_window_name, width=50, height=1) # 输入文件名称
self.name_data_Text.grid(row=3, column=1, rowspan=1, columnspan=20)
self.result_data_Text = Text(self.init_window_name, width=50, height=1) #输入文件内容
self.result_data_Text.grid(row=3, column=1, rowspan=5, columnspan=15)
#按钮
self.str_trans_to_md5_button = Button(self.init_window_name, text=" 创建 ", bg="lightblue", width=20,command=self.myfun) # 调用内部方法 加()为直接调用
self.str_trans_to_md5_button.grid(row=7, column=5)
def myfun(self):
path = str(self.init_data_Text.get(1.0,END).replace("\n","")) #'F:/test.txt'
mingming = str(self.name_data_Text.get(1.0,END).replace("\n",""))
text =self.result_data_Text.get(1.0,END).replace("\n","") # 'zhoayogndong'
file = open(path+"/"+mingming+".txt", 'w')
file.write(text)
print("创建完成")
def gui_start():
init_window = Tk() #实例化出一个父窗口
ZMJ_PORTAL = MY_GUI(init_window)
# 设置根窗口默认属性
ZMJ_PORTAL.set_init_window()
init_window.mainloop() #父窗口进入事件循环,可以理解为保持窗口运行,否则界面不展示
gui_start()
实现结果: