好友
阅读权限10
听众
最后登录1970-1-1
|
本帖最后由 Clinton 于 2020-4-2 17:12 编辑
前几天看见老哥发了一个,去下载没下载到,就自己写了一个,直接分享源码给大家吧。修复了bug.
import tkinter as tk
class MyApp(tk.Tk):
def __init__(self):
super().__init__()
self.title('header处理工具')
win_width = self.winfo_screenwidth()
win_height = self.winfo_screenheight()
my_width = 800
my_height = 560
x = (win_width - my_width) / 2
y = (win_height - my_height) / 2
self.geometry("%dx%d+%d+%d" % (my_width, my_height, x, y))
self.maxsize(my_width, my_height)
self.minsize(my_width, my_height)
self.button = tk.Button(self, text='转换', font=('宋体', 12), command=self.update)
self.button.place(x=380, y=300)
self.label1 = tk.Label(self, text='原始文本', font=('宋体', 10))
self.label1.place(x=160, y=5)
self.text1 = tk.Text(width=50, height=40)
self.text1.place(x=5, y=30)
self.label2 = tk.Label(self, text='结果文本', font=('宋体', 10))
self.label2.place(x=600, y=5)
self.text2 = tk.Text(width=50, height=40)
self.text2.place(x=440, y=30)
def update(self):
import tkinter.messagebox
if len(self.text1.get('0.0', 'end')) == 1:
tkinter.messagebox.showinfo('提示', '请先填入内容继续')
else:
self.text2.delete('1.0', 'end')
one_content = []
two_content = []
three_content = []
four_content = []
one_content = self.text1.get('0.0', 'end').split("\n")
for i in range(len(one_content)):
if one_content != '':
two_content.append(one_content)
else:
pass
for i in range(len(two_content)):
if two_content[0] == ':':
three_content.append(two_content[1:])
else:
three_content.append(two_content)
for i in range(len(three_content)):
if int(len(three_content)) == int(i + 1):
four_content.append("'" + three_content.replace(": ", "': '") + "'")
else:
four_content.append("'" + three_content.replace(": ", "': '") + "',")
for i in range(len(four_content)):
if int(len(four_content)) == int(i + 1):
self.text2.insert('insert', four_content)
else:
self.text2.insert('insert', four_content + '\n')
self.text2.update()
def main():
app = MyApp()
app.mainloop()
if __name__ == '__main__':
main()
|
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|