deepfacelab中文网

 找回密码
 立即注册(仅限QQ邮箱)
查看: 712|回复: 2

gpt写代码,复制器 !!!

[复制链接]

7

主题

25

帖子

212

积分

初级丹师

Rank: 3Rank: 3

积分
212
 楼主| 发表于 2023-11-23 15:27:31 | 显示全部楼层 |阅读模式
星级打分
  • 1
  • 2
  • 3
  • 4
  • 5
平均分: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按钮,达到修改内容名称的目的。




综上所述以此类推










image.png


  1. import tkinter as tk
  2. from tkinter import ttk
  3. import tkinter.simpledialog
  4. import json
  5. import random

  6. def copy_to_clipboard(content):
  7.     root.clipboard_clear()
  8.     root.clipboard_append(content)
  9.     content_text.delete('1.0', tk.END)
  10.     content_text.insert(tk.END, content)

  11. def update_contents(*args):
  12.     group = group_var.get()
  13.     contents = groups[group]
  14.     content_var.set(contents[0] if contents else '')
  15.     for widget in content_frame.winfo_children():
  16.         widget.destroy()
  17.     for content in contents:
  18.         button = ttk.Button(content_frame, text=content, command=lambda content=content: copy_to_clipboard(content))
  19.         button.pack(side='top')

  20. def add_group():
  21.     new_group = group_entry.get()
  22.     if new_group:
  23.         groups[new_group] = []
  24.         group_var.set(new_group)
  25.         group_button = ttk.Button(group_frame, text=new_group, command=lambda group=group: group_var.set(group))
  26.         group_button.pack(side='top')
  27.         category_menu['menu'].add_command(label=new_group, command=tk._setit(category_var, new_group))

  28. def add_content():
  29.     group = category_var.get()
  30.     new_content = content_entry.get()
  31.     if new_content:
  32.         groups[group].append(new_content)
  33.         content_var.set(new_content)
  34.         if group == group_var.get():
  35.             button = ttk.Button(content_frame, text=new_content, command=lambda content=new_content: copy_to_clipboard(content))
  36.             button.pack(side='top')

  37. root = tk.Tk()
  38. root.geometry('1024x768')
  39. root.title('copy')

  40. frame = ttk.Frame(root)
  41. frame.pack(fill='both', expand=True)

  42. content_label = ttk.Label(root, text='显示区')
  43. content_label.place(x=400, y=300, width=600, height=20)
  44. content_text = tk.Text(root)
  45. content_text.place(x=400, y=320, width=598, height=198)

  46. try:
  47.     with open('groups.json', 'r') as f:
  48.         groups = json.load(f)
  49. except FileNotFoundError:
  50.     groups = {}

  51. group_var = tk.StringVar()
  52. group_var.trace('w', update_contents)
  53. group_frame = ttk.LabelFrame(frame, text='分类区')
  54. group_frame.place(x=0, y=0, width=400, height=750)
  55. for group in groups.keys():
  56.     group_button = ttk.Button(group_frame, text=group, command=lambda group=group: group_var.set(group))
  57.     group_button.pack(side='top')

  58. content_var = tk.StringVar()
  59. content_frame = ttk.LabelFrame(frame, text='分类内容')
  60. content_frame.place(x=400, y=0, width=600, height=300)

  61. group_label = ttk.Label(frame, text='增加分类')
  62. group_label.place(x=400, y=520, width=100, height=20)
  63. group_entry = ttk.Entry(frame)
  64. group_entry.place(x=500, y=520, width=200, height=20)
  65. add_group_button = ttk.Button(frame, text='保存1', command=add_group)
  66. add_group_button.place(x=700, y=520, width=50, height=20)

  67. content_label = ttk.Label(frame, text='增加内容')
  68. content_label.place(x=400, y=540, width=100, height=20)
  69. content_entry = ttk.Entry(frame)
  70. content_entry.place(x=500, y=540, width=200, height=20)
  71. category_var = tk.StringVar()
  72. category_menu = ttk.OptionMenu(frame, category_var, *groups.keys())
  73. category_menu.place(x=700, y=540, width=100, height=20)
  74. add_content_button = ttk.Button(frame, text='保存2', command=add_content)
  75. add_content_button.place(x=800, y=540, width=50, height=20)

  76. if groups:
  77.     group_var.set(list(groups.keys())[0])

  78. root.mainloop()
复制代码



回复

使用道具 举报

20

主题

499

帖子

5万

积分

高级丹圣

Rank: 13Rank: 13Rank: 13Rank: 13

积分
52381

真我风采勋章

发表于 2023-11-23 18:16:09 | 显示全部楼层
用pyqt5很简单
回复 支持 反对

使用道具 举报

7

主题

235

帖子

1547

积分

初级丹圣

Rank: 8Rank: 8

积分
1547

万事如意节日勋章

发表于 2023-11-24 08:59:00 | 显示全部楼层
要么有钞能力,要么超有能力
不要问我爱不爱你
我的余光中里都是你
回复 支持 反对

使用道具 举报

QQ|Archiver|手机版|deepfacelab中文网 |网站地图

GMT+8, 2024-10-3 01:17 , Processed in 0.086561 second(s), 11 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表