|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- print(b)
- def corol():
- c = colorchooser.askcolor()
- print(c)
-
- a = Menu(root)
- f = Menu(root,tearoff=False)
- f.add_command(label='新建',command=c)
- f.add_command(label='打开',command=clall)
- f.add_command(label='保存',command=call)
- f.add_separator()
- f.add_command(label='关闭',command=root.quit)
- a.add_cascade(label='文件', menu=f)
- s = Menu(root,tearoff=False)
- s.add_command(label='颜色',command=corol)
- a.add_cascade(label='查看', menu=s)
- sb = Scrollbar(root)
- root.config(menu=a)
- text = Text(root, yscrollcommand=sb.set)
- sb.pack(side=RIGHT, fill=Y)
- sb.config(command=text.yview)
- text.pack()
- mainloop()
复制代码
怎么设置颜色
请指点
为了你的问题,我花 10 鱼币买了文档
- from tkinter import *
- from tkinter import filedialog
- from tkinter import colorchooser
- root = Tk()
- def c():
- text.delete(1.0, END)
- def clall():
- a = filedialog.askopenfilename()
- with open(a, encoding="utf-8") as file:
- text.delete(1.0, END)
- text.insert(INSERT, file.read())
- def call():
- b = filedialog.asksaveasfilename()
- with open(b, "w") as file:
- file.write(text.get(1.0, END))
- def corol():
- c = colorchooser.askcolor()
- text.tag_config("tag_1", background="white", foreground=c[1])
- content = text.get(1.0, END)
- text.delete(1.0, END)
- text.insert(END, content, "tag_1")
- a = Menu(root)
- f = Menu(root,tearoff=False)
- f.add_command(label='新建',command=c)
- f.add_command(label='打开',command=clall)
- f.add_command(label='保存',command=call)
- f.add_separator()
- f.add_command(label='关闭',command=root.quit)
- a.add_cascade(label='文件', menu=f)
- s = Menu(root,tearoff=False)
- s.add_command(label='颜色',command=corol)
- a.add_cascade(label='查看', menu=s)
- sb = Scrollbar(root)
- root.config(menu=a)
- text = Text(root, yscrollcommand=sb.set, )
- sb.pack(side=RIGHT, fill=Y)
- sb.config(command=text.yview)
- text.pack()
- mainloop()
复制代码
|
|