|
星级打分
平均分:NAN 参与人数:0 我的评分:未评
gpt写代码,哈哈,下面红色字是没有达到预期的其他都可以。我也不知道怎么沟通了,就是弄不好,有木有小伙伴弄下呀
我需要编写一个程序,1024*768,logo图标随机,程序名copy。
左边组合框名为分类区,分类区大小为400*750,
右上组合框名为分类内容区,大小600*300,
右中组合框名显示区,大小600*200,显示区里是编辑框3,大小598*198
右下第一行,标签名为“增加分类”然后是编辑框1,然后是保存1按钮
右下第二行,标签名为“增加内容”然后是编辑框2,然后是下拉框1,然后是保存2按钮。
我将举例说明逻辑关系,
假设在编辑框1输入“AAA”按下保存1按钮时,左边组合框分类区会新增一个100*50名为AAA的按钮,同时下拉列表增加AAA的选项,以此达到新增分类的目的。
当点击AAA分类按钮时,编辑框1同时刷新为AAA,修改内容为BBB再次点击保存1按钮那么AAA按钮将被更改为BBB按钮,达到修改按钮名称的目的。
假设在编辑框2输入:222,下拉列表选择分类AAA,按下保存2按钮时,那么按下AAA分类按钮时,分内内容区会新增一个大小100*50,名为222的按钮,点击222按钮会复制222到剪切板同时输出消息已复制在显示区里的编辑框里显示222。
点点击222按钮时,编辑框3,同时刷新为222,修改内容为333点击保存2按钮那么222按钮将被更改为333按钮,达到修改内容名称的目的。
综上所述以此类推
- import tkinter as tk
- from tkinter import ttk
- import tkinter.simpledialog
- import json
- import random
- def copy_to_clipboard(content):
- root.clipboard_clear()
- root.clipboard_append(content)
- content_text.delete('1.0', tk.END)
- content_text.insert(tk.END, content)
- def update_contents(*args):
- group = group_var.get()
- contents = groups[group]
- content_var.set(contents[0] if contents else '')
- for widget in content_frame.winfo_children():
- widget.destroy()
- for content in contents:
- button = ttk.Button(content_frame, text=content, command=lambda content=content: copy_to_clipboard(content))
- button.pack(side='top')
- def add_group():
- new_group = group_entry.get()
- if new_group:
- groups[new_group] = []
- group_var.set(new_group)
- group_button = ttk.Button(group_frame, text=new_group, command=lambda group=group: group_var.set(group))
- group_button.pack(side='top')
- category_menu['menu'].add_command(label=new_group, command=tk._setit(category_var, new_group))
- def add_content():
- group = category_var.get()
- new_content = content_entry.get()
- if new_content:
- groups[group].append(new_content)
- content_var.set(new_content)
- if group == group_var.get():
- button = ttk.Button(content_frame, text=new_content, command=lambda content=new_content: copy_to_clipboard(content))
- button.pack(side='top')
- root = tk.Tk()
- root.geometry('1024x768')
- root.title('copy')
- frame = ttk.Frame(root)
- frame.pack(fill='both', expand=True)
- content_label = ttk.Label(root, text='显示区')
- content_label.place(x=400, y=300, width=600, height=20)
- content_text = tk.Text(root)
- content_text.place(x=400, y=320, width=598, height=198)
- try:
- with open('groups.json', 'r') as f:
- groups = json.load(f)
- except FileNotFoundError:
- groups = {}
- group_var = tk.StringVar()
- group_var.trace('w', update_contents)
- group_frame = ttk.LabelFrame(frame, text='分类区')
- group_frame.place(x=0, y=0, width=400, height=750)
- for group in groups.keys():
- group_button = ttk.Button(group_frame, text=group, command=lambda group=group: group_var.set(group))
- group_button.pack(side='top')
- content_var = tk.StringVar()
- content_frame = ttk.LabelFrame(frame, text='分类内容')
- content_frame.place(x=400, y=0, width=600, height=300)
- group_label = ttk.Label(frame, text='增加分类')
- group_label.place(x=400, y=520, width=100, height=20)
- group_entry = ttk.Entry(frame)
- group_entry.place(x=500, y=520, width=200, height=20)
- add_group_button = ttk.Button(frame, text='保存1', command=add_group)
- add_group_button.place(x=700, y=520, width=50, height=20)
- content_label = ttk.Label(frame, text='增加内容')
- content_label.place(x=400, y=540, width=100, height=20)
- content_entry = ttk.Entry(frame)
- content_entry.place(x=500, y=540, width=200, height=20)
- category_var = tk.StringVar()
- category_menu = ttk.OptionMenu(frame, category_var, *groups.keys())
- category_menu.place(x=700, y=540, width=100, height=20)
- add_content_button = ttk.Button(frame, text='保存2', command=add_content)
- add_content_button.place(x=800, y=540, width=50, height=20)
- if groups:
- group_var.set(list(groups.keys())[0])
- root.mainloop()
复制代码
|
|