python GUI 简易示例

最近迷恋上python,正好看到一篇文章里面写到python的 可以用来写界面,所以随手写了一个分词的小工具,提供给大家拿来练练手。

下面是效果图

在这里插入图片描述

代码部分

# -*- coding: utf-8 -*-

from tkinter import *
import tkinter.messagebox

top = Tk()

top.title(“分词工具-v1.0.2”)

def btn_click():
# #复制来源文本框中的文本内容
data = text1.get(“1.0”, “end”)
data = str(data).replace(’\n’, ‘’)
data = data.strip()
arr_data = data.split(’ ')
arr_set = set(arr_data)
#去掉原先的数据
text2.delete(“1.0”, “end”)
for info in arr_set:
text2.insert(END, info + ‘\n’)
tkinter.messagebox.showinfo(‘提示’, ‘完成’)

class section2:
def init(self):
self.text = “”
def onCopy(self):
self.text = text2.get(‘1.0’, ‘end’)
top.clipboard_append(self.text)

#按钮
btn = Button(top,text=“分词”,width=10,height=1,command=btn_click)
btn.pack()

fup1 = Frame()
fup1.pack()
#-------------------------------
sc1 = Scrollbar(fup1)
sc1.pack(side=RIGHT,fill=Y)
text1 = Text(fup1)
text1.pack(expand=YES,fill=BOTH)
text1.config(yscrollcommand=sc1.set)

#-------------------------------
fup2 = Frame()
fup2.pack()

sc2 = Scrollbar(fup2)
sc2.pack(side=RIGHT,fill=Y)
text2 = Text(fup2)
text2.pack(expand=YES,fill=BOTH)
text2.config(yscrollcommand=sc2.set)

#按钮2
section2 = section2()
btn2 = Button(top,text=“复制”,width=10,height=1,command=section2.onCopy)
btn2.pack()

#窗口自身属性
top.geometry(“600x700”)
top.mainloop()

猜你喜欢

转载自blog.csdn.net/weixin_42152696/article/details/86015286
今日推荐