鱼C论坛

 找回密码
 立即注册
查看: 3745|回复: 17

[吹水] 两个精华

[复制链接]
发表于 2023-1-1 13:58:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
截屏2023-01-01 13.57.44.png
OHHHHHHHHHHHHHHHHHH!!!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-1-1 14:01:43 | 显示全部楼层
你在吧?
在我的帖子里帮我at下不二如是呗
我想申精
但是我权限不够没法加好友
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-1-1 14:02:41 | 显示全部楼层
liuhongrun2022 发表于 2023-1-1 14:01
你在吧?
在我的帖子里帮我at下不二如是呗
我想申精

okok
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-1-1 14:05:02 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-1-1 14:41:38 | 显示全部楼层
本帖最后由 liuhongrun2022 于 2023-1-1 18:51 编辑

我用二十分钟重做了一下win版的UI
登录界面
捕获.PNG
对比原版:
捕获.PNG
聊天界面
捕获1.PNG
对比原版:
无标题.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-1-1 15:59:28 | 显示全部楼层
帮我也at一下(我at你了)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-1-1 16:31:38 | 显示全部楼层
liuhongrun2022 发表于 2023-1-1 14:41
我用二十分钟重做了一下win版的UI  
登录界面

感谢!!!!!!!!!!!!!!!!!!!
你要什么
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-1-1 16:32:09 | 显示全部楼层
Mike_python小 发表于 2023-1-1 16:31
感谢!!!!!!!!!!!!!!!!!!!
你要什么

我却鱼币

评分

参与人数 2鱼币 +7 收起 理由
1molHF + 5
学习编程中的Ben + 2

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-1-1 16:38:24 | 显示全部楼层
Mike_python小 发表于 2023-1-1 16:31
感谢!!!!!!!!!!!!!!!!!!!
你要什么

你要源代码吗?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-1-1 16:40:31 | 显示全部楼层

要,私发我
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-1-1 16:49:16 | 显示全部楼层
Mike_python小 发表于 2023-1-1 16:31
感谢!!!!!!!!!!!!!!!!!!!
你要什么

发给你
  1. from tkinter import *
  2. import ttkbootstrap as ttk
  3. from ttkbootstrap.constants import *
  4. from tkinter import messagebox as mg
  5. import time
  6. import threading
  7. import socket

  8. def center_window(root, width, height):
  9.     """
  10.     窗口居中代码
  11.     """
  12.     screenwidth = root.winfo_screenwidth()  # 获取显示屏宽度
  13.     screenheight = root.winfo_screenheight()  # 获取显示屏高度
  14.     size = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)  # 设置窗口居中参数
  15.     root.geometry(size)  # 让窗口居中显示

  16. def fasong(*args):
  17.     time.sleep(0.1)
  18.     # re_data = input(">>")
  19.     re_data = send_entry.get("1.0", END)[:-1]
  20.     if 'exit' == re_data:   # 判断是否退出
  21.         client.send(("Q "+ username).encode())  # 发送退出的请求
  22.         client.close()

  23.     elif (re_data != " \n" and re_data != "\n" and re_data != "" and re_data != " "):    # 判断内容不为空
  24.         client.send(("C " + username + ": " + re_data).encode())
  25.         time_ = time.strftime('%Y-%m-%d %H:%M:%S')                  # 以下为自己说的话

  26.         chat_text.config(state=NORMAL)

  27.         #f1 = Font("微软雅黑 Light", 8)
  28.         chat_text.tag_config("tag_3", font=("MV boli", 9), foreground="grey")
  29.         chat_text.insert(END, time_, "tag_3")   # 发送时间
  30.         chat_text.insert(END, "\n")

  31.         #f = Font("微软雅黑 Light", 13)
  32.         chat_text.tag_config("tag_41", font=("微软雅黑 Light", 12), foreground="#808080")
  33.         chat_text.insert(END, username + ":", "tag_41")    # 发送文本内容
  34.         chat_text.insert(END, "\n")
  35.         
  36.         #f = Font("微软雅黑 Light", 12)
  37.         chat_text.tag_config("tag_4", font=("微软雅黑 Light", 12), foreground="#2E8B57")
  38.         chat_text.insert(END, re_data, "tag_4")    # 发送文本内容
  39.         chat_text.insert(END, "\n")

  40.         chat_text.config(state=DISABLED)
  41.         chat_text.see("end")    # 转到最后一行


  42.         # send_entry.first()
  43.         # send_entry.delete(0.1,2.0)      # 设置发送为空
  44.         # send_entry.insert('1 wordstart' , "s")
  45.         # time.sleep(0.1)
  46.         send_entry.delete("0.0", END)   # 设置发送为空


  47. def fa_(*args):
  48.     fasong()
  49.     # send_entry.delete("0.0", END)   # 设置发送为空
  50.     return 'break'




  51. def jieshou():
  52.     while True:
  53.         # time.sleep(0.3)
  54.         try:
  55.             data = client.recv(1024)
  56.             res = data.decode()
  57.             if(res != ''):

  58.                 # print("1")
  59.                 if (res.split(" ", 2)[0]=="C"): # 如果为聊天的请求
  60.                     # print(res.split(" ", 1)[0])
  61.                     # print(res.split(" ", 1)[1])
  62.                     # print(res)
  63.                     time_ = time.strftime('%Y-%m-%d %H:%M:%S')

  64.                     chat_text.config(state=NORMAL)

  65.                     #f1 = Font("微软雅黑 Light", 10)
  66.                     chat_text.tag_config("tag_1", font=("MV Boli", 9), foreground="grey")   
  67.                     chat_text.insert(END, time_, "tag_1")
  68.                     chat_text.insert(END, "\n")

  69.                     #f = Font("微软雅黑 Light", 13)
  70.                     chat_text.tag_config("tag", font=("微软雅黑 Light", 12), foreground="#808080")
  71.                     chat_text.insert(END, res.split(" ", 2)[1], "tag")
  72.                     chat_text.insert(END, "\n")
  73.                     
  74.                    #f = Font("微软雅黑 Light", 12)
  75.                     chat_text.tag_config("tag_2", font=("微软雅黑 Light", 12))
  76.                     chat_text.insert(END, res.split(" ", 2)[2], "tag_2")
  77.                     chat_text.insert(END, "\n")

  78.                     chat_text.config(state=DISABLED)
  79.                     chat_text.see("end")


  80.                 elif(res.split(" ", 1)[0]=="R"):    # 在线用户请求
  81.                     afd = False
  82.                     print(res.split(" ", 1)[1])
  83.                     for kk in range(0, online_user.size()): # 循环判断在线列表里是否有用户名
  84.                         if online_user.get(kk) == (res.split(" ", 1)[1]):   # 检测到是
  85.                             afd = True  # 判断变量为真
  86.                             break   # 退出
  87.                     if (afd ==  False): # 如果判断变量为假
  88.                         online_user.insert(END,res.split(" ", 1)[1])    # 插入用户名


  89.                 elif(res.split(" ", 1)[0]=="E"):    # 退出请求
  90.                     for kk in range(0, online_user.size()): # 循环判断要删除的用户名
  91.                         if online_user.get(kk) == (res.split(" ", 1)[1]):   
  92.                             online_user.delete(kk)  # 从在线列表去除
  93.                             break
  94.                         


  95.         # else:
  96.         #     continue
  97.         except Exception as e:  
  98.             print(e)
  99.             print("客户端已退出")
  100.             #break

  101. def send():
  102.     """
  103.     发送文字
  104.     """
  105.     global username
  106.     username = username_string.get()    # 用户名变量
  107.     # time.sleep(3)


  108.     if __name__ == "__main__":
  109.         # print("Welcome to Gouzi WD Chat")
  110.         # print(username)
  111.         #注册业务
  112.         while True:
  113.             # username=input("请输入用户名")
  114.             if ' ' not in username and username != " " and username != "":  # 判断用户名不为空
  115.                 client.send(("R "+username + " " + password_string.get()+"\n").encode())   # 发送注册请求
  116.                 data=client.recv(2048).decode() # 最大接受字节

  117.                 if data=="OK":  # 如果穿回信息为 “OK”
  118.                     break
  119.             else:
  120.                 mg.showerror("", "用户名不能为空,请强制退出后重新进入")    # 用户名如果为空,发出警告
  121.                


  122.         try:
  123.             # 创建一个新的线程
  124.             new_thread = threading.Thread(target=jieshou, name="T1")   
  125.             # 启动新线程
  126.             new_thread.start()


  127.             new_thread1 = threading.Thread(target=fasong, name="T2")
  128.             # 启动新线程
  129.             new_thread1.start()
  130.         except:
  131.             client.close()

  132. def insert_newline(*args):
  133.     send_entry.insert("insert", "\n")
  134.     return "break"

  135. def main():
  136.     """
  137.     加入聊天后界面
  138.     """
  139.     global chat_text, send_msg, online_user, send_entry
  140.     root = Toplevel()
  141.     root.title("聊天界面")
  142.     center_window(root, 800, 500)

  143.     send_msg = StringVar()


  144.     """
  145.     ——————————————————————————
  146.     查收文件text开始
  147.     """

  148.     frame = Frame(root)
  149.     frame.place(x = 20, y = 20)

  150.     gun_song_tiao_y = Scrollbar(frame)
  151.     gun_song_tiao_x = Scrollbar(frame, orient=HORIZONTAL)
  152.     chat_text = Text(frame, height=12, width=44, wrap='none', relief=GROOVE, state=DISABLED, font=('微软雅黑 Light', 14))#, state=DISABLED

  153.     gun_song_tiao_y.pack(side=RIGHT,fill=Y)
  154.     gun_song_tiao_x.pack(side=BOTTOM, fill=X)

  155.     chat_text.pack()

  156.     gun_song_tiao_y.config(command=chat_text.yview)
  157.     gun_song_tiao_x.config(command=chat_text.xview)

  158.     chat_text.config(yscrollcommand=gun_song_tiao_y.set)
  159.     chat_text.config(xscrollcommand=gun_song_tiao_x.set)

  160.     """
  161.     查收文件区域text结束
  162.     ——————————————————————————
  163.     """



  164.     send_entry = Text(root, width=67, height=4) # 发送区域
  165.     send_entry.place(x=20, y=500)


  166.     send_button = ttk.Button(root, text="发送", bootstyle='info-outline', width=5, command=fa_)     # 发送按钮
  167.     send_button.place(x=690, y=545)

  168.     send_entry.bind("<Return>", fa_)
  169.     send_entry.bind("<Control-Return>", insert_newline)

  170.     online_user = Listbox(root, height=17)
  171.     online_user.place(x=770, y=30)
  172.     online_user.insert(END, '在线成员列表')

  173.     root.geometry('1000x620')

  174. def help():
  175.     """
  176.     帮助界面
  177.     """
  178.     mg.showerror("暂无", "NONE")

  179. def if_login(*args):
  180.     main()
  181.     send()

  182. def if_res():
  183.     pass

  184. def login():
  185.     """注册/登陆"""
  186.     global username_string
  187.     global username_string, password_string
  188.     global client

  189.     root = ttk.Window()
  190.     center_window(root, 400, 300)   # 实现页面居中
  191.     root.title("Gouzi WD在线聊天室")    # 标题

  192.     client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  193.     client.connect(('43.138.0.102', 80))

  194.     username_string = StringVar()   # 存储用户名变量
  195.     password_string = StringVar()   # 密码存储变量

  196.     Label(root, text="登陆界面", font=("得意黑", 20)).place(x=130, y=30)  # 表头


  197.     Label(root, text="用户名:", font=("得意黑", 14)).place(x=10, y=100)  # 用户名一栏
  198.     username = ttk.Entry(root, bootstyle='primary', textvariable=username_string)    #用户名ttk.Entry
  199.     username.place(x=110, y=100)

  200.     Label(root, text="密码:", font=("得意黑", 14)).place(x=10, y=150)  # 密码一栏
  201.     password = ttk.Entry(root, bootstyle='primary', textvariable=password_string)    # 密码ttk.Entry
  202.     password.place(x=110, y=150)

  203.     username.bind("<Return>", if_login)
  204.     password.bind("<Return>", if_login)



  205.     join_button = ttk.Button(root, text="登陆", bootstyle='warning-outline',command=if_login)    # 进入聊天界面按钮
  206.     join_button.place(x=60, y=200)

  207.     res_button = ttk.Button(root, text="注册", bootstyle='success-outline',command=if_res)    # 注册
  208.     res_button.place(x=230, y=200)

  209.     # if_login()


  210.     root.mainloop()

  211. login()





  212. # def login():
  213. #     """
  214. #     登陆界面,也是初始界面
  215. #     """
  216. #     root = Tk()
  217. #     center_window(root, 400, 500)   # 实现页面居中
  218. #     root.title("Gouzi WD在线聊天室")    # 标题

  219. #     username_string = StringVar()   # 存储用户名变量
  220. #     ip_string = StringVar() # ip存储变量
  221. #     password_string = StringVar()   # 密码存储变量

  222. #     Label(root, text="初始界面", font=("微软雅黑 Light", 20)).place(x=130, y=30)  # 表头


  223. #     Label(root, text="用户名:", font=("微软雅黑 Light", 14)).place(x=10, y=100)  # 用户名一栏
  224. #     username = ttk.Entry(root, textvariable=username_string)    #用户名ttk.Entry
  225. #     username.place(x=110, y=100)

  226. #     Label(root, text="ip:", font=("微软雅黑 Light", 14)).place(x=10, y=150)  # ip一栏
  227. #     ip = ttk.Entry(root, textvariable=ip_string)    #ipttk.Entry
  228. #     ip.place(x=110, y=150)

  229. #     Label(root, text="ip密码(选填):", font=("微软雅黑 Light", 14)).place(x=10, y=200)  # 密码一栏
  230. #     password = ttk.Entry(root, textvariable=password_string)    # 密码ttk.Entry
  231. #     password.place(x=110, y=200)

  232. #     Label(root, text="预留位:", font=("微软雅黑 Light", 14)).place(x=10, y=250)  # 预留一栏
  233. #     password = ttk.Entry(root)    # 预留ttk.Entry
  234. #     password.place(x=110, y=250)

  235. #     join_button = ttk.Button(root, text="进入", command=join, font=("微软雅黑 Light", 12))    # 进入聊天界面按钮
  236. #     join_button.place(x=160, y=300)

  237. #     help_button = ttk.Button(root, text="帮助", font=("微软雅黑 Light", 9), command=help)   # 帮助按钮
  238. #     help_button.place(x=163, y=350)
  239. #     # join()

  240. #     root.mainloop()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-1-1 16:56:02 | 显示全部楼层

万分感谢!!!!!!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-1-1 17:04:28 | 显示全部楼层
Mike_python小 发表于 2023-1-1 16:56
万分感谢!!!!!!

代码里有个“得意黑”字体
你没有就把他换成别的
不会太难看
或者下载这个字体

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-1-1 17:26:29 | 显示全部楼层

没平分了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2023-1-1 17:28:05 | 显示全部楼层
liuhongrun2022 发表于 2023-1-1 17:04
代码里有个“得意黑”字体
你没有就把他换成别的
不会太难看

这个ttkbootstrap的什么操作都与tkinter一样吗?比如entry的读取
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-1-1 17:33:25 | 显示全部楼层
小鱼有你更精彩
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-1-1 17:33:43 | 显示全部楼层
本帖最后由 liuhongrun2022 于 2023-1-1 18:33 编辑
Mike_python小 发表于 2023-1-1 17:28
这个ttkbootstrap的什么操作都与tkinter一样吗?比如entry的读取


差不多
你完全可以用ttkbootstrap来代替tkinter
推荐阅读:https://blog.csdn.net/qq_59142194/article/details/123937365
和 https://ttkbootstrap.readthedocs.io/en/latest/zh/styleguide/
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-1-1 17:43:12 | 显示全部楼层
感谢您帮忙at,我也双精了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-24 21:50

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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