用户:L0_0查看:0 回复:0 评论:0 创建时间:2021-03-27T19:14:35
【作品展示】

【作品介绍】
tkinter作品
【作品源代码】
import math
import traceback
from tkinter import Tk, Menu, Text, Label, Scrollbar, messagebox
root = Tk()
root.title('python')
l = Label(root, width=115, text='1', anchor='w')
l.pack(side='bottom')
t = Text(root, font='默认')
t.pack(side='left', fill='y')
s = Scrollbar(root)
s.pack(side='right', fill='y')
def count_line(event):
l['text'] = math.floor(float(t.index('insert')))
s.config(command=t.yview)
t.config(yscrollcommand=s.set)
root.bind('', count_line)
def run():
print('------------------start------------------')
try:
exec(t.get('0.0', 'end'))
except:
traceback.print_exc()
messagebox.showerror('错误', traceback.format_exc())
print('-------------------end-------------------')
def copy():
global copy_text
copy_text = t.selection_get()
def paste():
t.insert(t.index('insert'), copy_text)
menubar = Menu(root)
pythonmenu = Menu(menubar, tearoff=0)
pythonmenu.add_command(label='运行', command=run)
pythonmenu.add_separator()
pythonmenu.add_command(label='复制', command=copy)
pythonmenu.add_command(label='粘贴', command=paste)
pythonmenu.add_separator()
pythonmenu.add_command(label='退出', command=root.quit)
menubar.add_cascade(label='选项', menu=pythonmenu)
root.config(menu=menubar)
copy_text = ''
menu=Menu(root, tearoff=0)
menu.add_command(label='复制', command=copy)
menu.add_command(label='粘贴', command=paste)
def popupmenu(event):
menu.post(event.x_root, event.y_root)
root.bind('', popupmenu)
root.mainloop()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn