python3 tkinter_Python3 tkinter初级

名称描述取值范围

anchor

相对于摆放组件的坐标的位置

请参阅:可能是N,E,S,W,东北,西北,东南或西南,罗盘方向指示的widget的角落,双方默认是净重(部件上左上角)

height

以像素为单位的高度.(绝对布局专用)

像素

width

以像素为单位的宽度.(绝对布局专用)

像素

relheight

组件相对于窗口的的高度(相对布局专用)

0~1

relwidth

组件相对于窗口的的宽度(相对布局专用)

0~1

relx

水平偏移为0.0和1.0之间浮动,父widget的一小部分的高度和宽度.(相对布局专用)

0~1

rely

垂直偏移为0.0和1.0之间浮动,父widget的一小部分的高度和宽度.(相对布局专用)

0~1

x

组件距离左上角的x坐标(绝对布局专用)

像素

y

组件距离左上角的y坐标(绝对布局专用)

像素

place类提供了下列函数(使用组件实例对象调用)

函数名描述

place_slaves()

以列表方式返回本组件的所有子组件对象。

place_configure(option=value)

给pack布局管理器设置属性,使用属性(option)= 取值(value)方式设置

propagate(boolean)

设置为True表示父组件的几何大小由子组件决定(默认值),反之则无关。

place_info()

返回pack提供的选项所对应得值。

grid_forget()

Unpack组件,将组件隐藏并且忽略原有设置,对象依旧存在,可以用pack(option, …),将其显示。

location(x, y)

x, y为以像素为单位的点,函数返回此点是否在单元格中,在哪个单元格中。返回单元格行列坐标,(-1, -1)表示不在其中

size()

返回组件所包含的单元格,揭示组件大小。

组件1 按钮(button)

用于定义GUI界面中的按钮组件

"""tkinter.Button(用于存放的父组件,属性参数...)"""

具备以下属性

"""anchor 设置按钮中文字的对齐方式,相对于按钮的中心位置

background(bg) 设置按钮的背景颜色

foreground(fg) 设置按钮的前景色(文字的颜色)

borderwidth(bd) 设置按钮边框宽度

cursor 设置鼠标在按钮上的样式

command 设定按钮点击时触发的函数

bitmap 设置按钮上显示的位图

font 设置按钮上文本的字体

width 设置按钮的宽度 (字符个数)

height 设置按钮的高度 (字符个数)

state 设置按钮的状态

text 设置按钮上的文字

image 设置按钮上的图片"""

代码示例:

import tkinter

# 创建一个主窗口

win=tkinter.Tk()

# 设置标题

win.title("Python-14")

# 设置窗口大小和位置

# 500x500表示窗口大小

#+200+50表示窗口距离电脑屏幕的左边缘和上边缘的距离

win.geometry("500x500+200+50")

button1=tkinter.Button(win,

text= "退出",

width= 20,

height= 5,

command=win.quit

)

button1.pack()

def func():

print("欢迎欢迎!")

button2=tkinter.Button(win,

text= "点我有惊喜",

width= 30,

height= 20,

command=func

)

button2.pack()

# 启动主窗口

win.mainloop()

组件2 文本框(Entry)和多行文本(Text)

用于定义页面中文本的单行输入框

"""#单行文本

tkinter.Entry(用于存放的父组件,属性参数...)

#多行文本

tkinter.Text(用于存放的父组件,属性参数...)"""

具备以下属性

"""background(bg) 设置文本框的背景色

foreground(fg) 设置文本框的前景色

borderwidth(bd) 设置文本输入框的边框

font 设置文本框中的字体

width 设置文本框的宽度(字符个数)

height 设置文本框的高度(字符个数),仅限于text

state 设置文本框的状态

selectbackground 选中文字时文本框的背景色

selectforeground 选中文字时文字的颜色

show 指定文本框显示的字符,若为*,则表示为密码框

textvariable 设置文本对应的变量,可以通过修改变量改变文字显示。必须使用tkinter.IntVar() 或 tkinter.StringVar()产生的变量 entry可以使用"""

代码示例:

import tkinter

# 创建一个主窗口

win=tkinter.Tk()

# 设置标题

win.title("Python-14")

# 设置窗口大小和位置

win.geometry("500x500+250+150")

# 设置一个变量,用来接收输入控件得内容

e1=tkinter.Variable()

# 输入框控件

# show 隐藏输入的内容

entry= tkinter.Entry(win,textvariable = e1,show = "@")

entry.pack()

# 设置输入框内默认内容

e1.set("请输入用户名")

print(e1.get())

#设置按钮提交

def func():

print(e1.get())

button= tkinter.Button(win,text = "提交",command =func)

button.pack()

# 启动主窗口

win.mainloop()

代码示例:

import tkinter

win=tkinter.Tk()

win.title("Python-14")

win.geometry("500x500+200+100")

#创建一个滚动条

scroll=tkinter.Scrollbar()

text= tkinter.Text(win,width = 100,height = 40)

#显示滚动条位置 放在右侧 填充满Y轴

scroll.pack(side= tkinter.RIGHT,fill =tkinter.Y)

# 文本框的显示

text.pack(side= tkinter.LEFT,fill =tkinter.Y)

#绑定滚动条和文本框

scroll.config(command=text.yview)

#绑定文本框和滚动条

text.config(yscrollcommand= scroll.set)

str= """Christmas Day is on December 25th. It was originated in the western country, but today, this festival has been celebrated by the world. For the manufacturers, they are very happy to make this day asa shopping day. I enjoy the great atmosphere.

I had a very special Christmas day last year. I experienced the western style festival. There was anew foreign teacher taught us the lesson. She was about 50 years old and she was very kind and we all liked her. On Christmas Day, she brought us the desserts she made early in the morning. We enjoyed the home-made cakes. What's more, she invited us to came to her house and spent the day with her. Then for the first time, I ate big turkey, which was so delicious. The turkey was filled with many stuffs and the flavor was so good. After dinner, we sang songs and danced. Thanks to my foreign teacher, I experienced the American style festival. It was such funny for me. Though today many people enjoy shopping in all kinds of festivals, the meaning of these festival should be remembered. Christmas Day is on December 25th. It was originated in the western country, but today, this festival has been celebrated by the world. For the manufacturers, they are very happy to make this day as a shopping day. I enjoy the great atmosphere.

I had a very special Christmas day last year. I experienced the western style festival. There was a new foreign teacher taught us the lesson. She was about 50 years old and she was very kind and we all liked her. On Christmas Day, she brought us the desserts she made early in the morning. We enjoyed the home-made cakes. What's more, she invited us to came to her house and spent the day with her. Then for the first time, I ate big turkey, which was so delicious. The turkey was filled with many stuffs and the flavor was so good. After dinner, we sang songs and danced. Thanks to my foreign teacher, I experienced the American style festival. It was such funny for me. Though today many people enjoy shopping in all kinds of festivals, the meaning of these festival should be remembered. Christmas Day is on December 25th. It was originated in the western country, but today, this festival has been celebrated by the world. For the manufacturers, they are very happy to make this day as a shopping day. I enjoy the great atmosphere.

I had a very special Christmas day last year. I experienced the western style festival. There was a new foreign teacher taught us the lesson. She was about 50 years old and she was very kind and we all liked her. On Christmas Day, she brought us the desserts she made early in the morning. We enjoyed the home-made cakes. What's more, she invited us to came to her house and spent the day with her. Then for the first time, I ate big turkey, which was so delicious. The turkey was filled with many stuffs and the flavor was so good. After dinner, we sang songs and danced. Thanks to my foreign teacher, I experienced the American style festival. It was such funny for me. Though today many people enjoy shopping in all kinds of festivals, the meaning of these festival should be remembered."""text.insert(tkinter.INSERT,str)

win.mainloop()

代码示例:

import tkinter

win=tkinter.Tk()

win.title("Python-14")

win.geometry("500x500+200+100")

# 创建一个输入框

entry=tkinter.Entry(win)

entry.pack()

# 创建一个文本框

text= tkinter.Text(win,width = 50,height = 20)

text.pack()

# 写一个读取文件的函数

def func():

with open(entry.get(),"r") asf:

content=f.read()

text.insert(tkinter.INSERT,content)

# 写一个保存文件内容的函数

def func1():

with open(entry.get(),"w") asf:

# 写入的内容为 文本框内从0行0列到结束

f.write(text.get(0.0,tkinter.END))

#创建两个按钮

button1= tkinter.Button(win,text = "保存",command =func1)

button2= tkinter.Button(win,text = "读取",command =func)

button1.pack()

button2.pack()

win.mainloop()

组件3 标签(Lebal)

标签用语在页面中显示文字或者图片

"""tkinter.Label(用于存放的父组件,属性参数...)"""

具备以下属性

"""anchor 设置文本相对于标签中心的位置

background(bg) 设置标签的背景色

foreground(fg) 设置标签的前景色

borderwidth(bd) 设置标签的边框宽度

width 设置标签的宽度(字符个数)

height 设置标签的高度(字符个数)

text 设置标签中文本内容

font 设置标签中文字的字体类型

bitmap 设置标签的现实的位图

image 设置标签中显示的图片

justify 设置标签中多行文本的对齐方式

textvariable 设置文本对应的变量,可以通过修改变量改变文字显示,必须使用tkinter.IntVar() 或者tkinter.StringVar()产生的变量"""

代码示例:

import tkinter

# 创建一个主窗口

win=tkinter.Tk()

# 设置标题

win.title("Python-14")

# 设置窗口大小和位置

# 500x500表示窗口大小

#+200+50表示窗口距离电脑屏幕的左边缘和上边缘的距离

win.geometry("500x500+200+50")"""Label:标签空间,可以显示文本

win:主窗口

text:显示文本内容

bg:背景颜色

fg:字体颜色

font:设置字体和字体大小

wraplength:指定text中多宽之后进行换行

anchor:文本显示的位置 n北 e东 s南 w西 center居中 ne se sw nw

justify:设置换行之后的对齐方式"""label =tkinter.Label(win,

text= "this is a python test",

bg= "red",

fg= "yellow",

font= ("黑体",26),

width= 5,

height= 10,

wraplength= 100,

anchor= "n",

justify= "right")

# 显示标签

label.pack()

# 启动主窗口

win.mainloop()

组件4 单选框(Radiobutton)与复选框(Checkbutton)

"""thinter.Radiobutton(用于存放的父组件,属性参数...)

thinter.Checkbutton(用于存放的父组件,属性参数...)"""

具有以下属性

"""anchor 设置组件中文字的对齐方式

background(bg) 指定组件的背景色。

borderwidth(bd) 指定组件边框的宽度。

bitmap 指定组件中的位图。

font 指定组件中文本的字体。

foreground(fg) 指定组件的前

height 指定组件的高度。

image 指定组件中的图片。

justify 指定组件中多行文本的对齐方式。

text 指定组件中的文本,可以 使用“\ n” 表示换行。

value 指定组件被选中后状态的值(单选框)

onvalue 组件勾选状态值(复选框)

offvalue 组件取消勾选状态的值(复选框)

variable 指定组件所关联的变量。需要使用tkinter. IntVar()或者tkinter. StringVar()创建的值

width 指定组件的宽度。

command 设置复选框操作的触发命令(复选框)"""

代码示例:

# 复选框

import tkinter

win=tkinter.Tk()

win.title("Python-14")

win.geometry("500x500+200+100")

def func():

message= ""

if res1.get():

message+= "张三\n"

if res2.get():

message+= "李四\n"

if res3.get():

message+= "王五\n"# 清除text中所有内容

text.delete(0.0,tkinter.END)

# 把message写入text中

text.insert(tkinter.INSERT,message)

# 判断复选框是否被选定 返回一个bool值

res1=tkinter.BooleanVar()

# 创建一个复选框

check1= tkinter.Checkbutton(win,text = "张三",variable =res1)

check1.pack()

res2=tkinter.BooleanVar()

check2= tkinter.Checkbutton(win,text = "李四",variable =res2)

check2.pack()

res3=tkinter.BooleanVar()

check3= tkinter.Checkbutton(win,text = "王五",variable =res3)

check3.pack()

# 创建一个文本框

text= tkinter.Text(win,width = 50,height = 20)

text.pack()

# 创建一个按钮

button= tkinter.Button(win,text = "submit",width = 10,height = 5,command =func)

button.pack()

win.mainloop()

代码示例:

#单选框

import tkinter

win=tkinter.Tk()

win.title("Python-14")

win.geometry("500x500+200+100")

# 获取单选框的value

res=tkinter.StringVar()

# 定义一个函数 来打印单选框的value值

def func():

print(res.get())

# 创建单选框

radio1=tkinter.Radiobutton(

win,

text= "张三",

value= 1,

variable=res,

command=func

)

radio2=tkinter.Radiobutton(

win,

text= "李四",

value= 2,

variable=res,

command=func

)

radio3=tkinter.Radiobutton(

win,text= "王五",

value= 3,

variable=res,

command=func

)

# 显示单选框

radio1.pack()

radio2.pack()

radio3.pack()

win.mainloop()

组件5 Frame 框架

"""thinter.Menu(用于存放的父组件,属性参数...)"""

具有以下属性

"""background(bg) 正常的背景颜色显示在标签和指示器后面。

borderwidth(bd) 指标周围边界的大小。默认值为2像素。

cursor 如果将此选项设置为光标名称(箭头,点等),则鼠标光标将在检查按钮上方更改为该模式。

height 新框架的垂直尺寸。

highlightbackground 当框架没有焦点时,焦点的颜色突出显示。

highlightcolor 当框架具有焦点时,焦点突出显示的颜色。

highlightthickness 焦点亮点的厚度。

relief 使用默认值,relief=FLAT,检查按钮不会从背景中脱颖而出。您可以将此选项设置为任何其他样式

width checkbutton的默认宽度取决于所显示的图像或文字的大小。你可以设置此选项的字符数和checkbutton的,总是有许多字符的空间。"""

代码示例:

#布局

import tkinter

win=tkinter.Tk()

win.title("Pyhton-14")

win.geometry("500x500+200+100")

# 创建一个框架

frame=tkinter.Frame(win)

frame.pack()

# 左边

frm1=tkinter.Frame(frame)

lable1= tkinter.Label(frm1,text = "左上",bg = "red",width = 10,height = 5)

lable2= tkinter.Label(frm1,text = "左下",bg = "yellow",width = 10,height = 5)

lable1.pack(side=tkinter.TOP)

lable2.pack(side=tkinter.TOP)

frm1.pack(side=tkinter.LEFT)

# 右边

frm2=tkinter.Frame(frame)

lable3= tkinter.Label(frm2,text = "右上",bg = "green",width = 10,height = 5)

lable4= tkinter.Label(frm2,text = "右下",bg = "blue",width = 10,height = 5)

lable3.pack(side=tkinter.TOP)

lable4.pack(side=tkinter.TOP)

frm2.pack(side=tkinter.RIGHT)

win.mainloop()

代码示例:

#绝对定位

import tkinter

win=tkinter.Tk()

win.geometry("500x500+200+100")

lable1= tkinter.Label(win,text = "小红",bg = "red",width = 20,height = 10)

lable2= tkinter.Label(win,text = "小明",bg = "green",width = 20,height = 10)

lable3= tkinter.Label(win,text = "李雷",bg = "yellow",width = 20,height = 10)

lable1.place(x= 0,y = 0)

lable2.place(x= 370,y = 0)

lable3.place(x= 0,y = 310)

win.mainloop()

代码示例:

#相对定位

import tkinter

win=tkinter.Tk()

win.title("Python-14")

win.geometry("500x500+200+100")

label1= tkinter.Label(win,text = "小红",bg = "red")

label2= tkinter.Label(win,text = "小明",bg = "green")

label3= tkinter.Label(win,text = "李雷",bg = "yellow")

label1.pack(fill= tkinter.Y,side =tkinter.LEFT)

label2.pack(fill= tkinter.Y,side =tkinter.RIGHT)

label3.pack(fill= tkinter.X,side =tkinter.TOP)

label3.pack()

win.mainloop()

代码示例:

#表格布局

import tkinter

win=tkinter.Tk()

win.title("Python-14")

win.geometry("500x500+200+100")

lable1= tkinter.Label(win,text = "小红",bg = "red")

lable2= tkinter.Label(win,text = "小黄",bg = "yellow")

lable3= tkinter.Label(win,text = "小蓝",bg = "blue")

lable4= tkinter.Label(win,text = "小粉",bg = "pink")

# 表格布局

lable1.grid(row= 0,column = 0)

lable2.grid(row= 0,column = 1)

lable3.grid(row= 1,column = 0)

lable4.grid(row= 1,column = 1)

win.mainloop()

事件绑定

之前能够触发操作的只有2个组件,一个按钮一个菜单的选项卡 command属性 设置操作对应的函数

鼠标事件类型

""" 按下了鼠标左键

按下了鼠标中键

按下了鼠标右键

鼠标进入组件区域鼠标离开组件区域释放了鼠标左键释放了鼠标中键释放了鼠标右键按住鼠标左键移动按住鼠标中键移动按住鼠标右键移动双击鼠标左键双击鼠标中键双击鼠标右键

三击鼠标左键

三击鼠标右键滚动鼠标滚轮"""

键盘事件类型

"""表示任何键盘按下表示按下键盘A键 A可以设置为其他的按键表示同时按下Alt和A键 A可以设置为其他的按键表示同时按下Ctrl和A键 A可以设置为其他的按键表示同时按下Shift和A键 A可以设置为其他的按键表示双击键盘A键 A可以设置为其他的按键表示开启大写之后键盘A键 A可以设置为其他的按键 表示同时按下alt+Ctrl和A键 A可以设置为其他的按键

注意:键盘事件除了entry和text组件其他组件的事件最好绑定在主界面上"""

事件对象中包含的信息

"""x,y 当前触发事件时鼠标相对触发事件的组件的坐标值

x_root,y_root 当前触发事件时鼠标相对于屏幕的坐标值char获取当前键盘事件时按下的键对应的字符

keycode 获取当前键盘事件时按下的键对应的的ascii码

type 获取事件的类型

num 获取鼠标按键类型123左中右

widget 触发事件的组件

width/height 组件改变之后的大小和configure()相关"""

窗口和组件相关事件类型

"""Activate 当中组件由不可以用变为可用时 针对于state的变值

Deactivate 当组件由可用变为不可用时触发

Configure 当组件大小发生变化时触发

Destory 当组件销毁时触发

FocusIn 当组件获取焦点时触发 针对于Entry和Text有效

Map 当组件由隐藏变为显示时触发

UnMap 当组件由显示变为隐藏时触发

Perproty 当窗口属性发生变化时触发"""

事件绑定函数

组件.bind('事件类型',事件函数)

#为一个组件绑定一个操作

组件.bind_class('组件类型','事件类型',事件函数)

#为一类组件绑定一个操作

#组件类型就是创建组件的方法名 例如按钮组件:Button

组件.bind_all('事件类型',事件函数)

#为所有组件绑定一个操作(所有操作都会当作对主界面的操作)

代码示例:

import tkinter

win=tkinter.Tk()

win.title("Python-14")

win.geometry("500x500+200+100")

def func(event):

print(event.x,event.y)

button= tkinter.Button(win,text = "按钮",width = 50,height = 20)

button.bind("",func)

button.pack()

win.mainloop()

练习

文件对比

import sys

import difflib

# sys.argv : 获取外部运行时的命令 返回一个列表

# sys.argv : 获取外部运行时的命令 返回一个列表

# print(sys.argv)

#

# file1= sys.argv[1]

# file2= sys.argv[2]

# print(file1)

# print(file2)

# difflib

# 创建比对对象 HtmlDiff() 生成一个html文件

# 比对内容 make_file()

代码示例:

import sys

import difflib

# sys.argv : 获取外部运行时的命令 返回一个列表

# sys.argv : 获取外部运行时的命令 返回一个列表

# print(sys.argv)

# difflib

# 创建比对对象 HtmlDiff() 生成一个html文件

# 比对内容 make_file()

first_path= sys.argv[1] # 获取第一个要比对的文件名称

next_path= sys.argv[2] # 获取第二个要比对的文件名称

# 分别读取两个文件

with open(first_path,"r") asf:

first_list=f.readlines()

with open(next_path,"r") asf:

next_list=f.readlines()

# 生成比对对象

diff=difflib.HtmlDiff()

html=diff.make_file(first_list,next_list)

with open("diff.html","w") asf:

f.write(html)

示例:

# win+R cmd cd到文件当前地址

# python 文件名.py 文件1 文件2

计算器

from tkinter import *root=Tk()

root.geometry('250x380')

root.title('计算器')

frame_show= Frame(width=300,height=150,bg='#dddddd')

#顶部区域

v=StringVar()

v.set('0')

show_label= Label(frame_show,textvariable =v, bg = 'white',width=12,height=1,font=("黑体", 20, "bold"),justify=LEFT,anchor='e')

show_label.pack(padx= 10,pady = 10)

frame_show.pack()

#是否按下了运算符

isopear=False

#操作序列

calc=[]

def change(num):globalisopearif isopear ==False:if v.get() == '0':

v.set('')

v.set(num)else:

v.set(v.get()+num)else:

v.set(num)

isopear=False

#运算

def operation(sign):globalisopearglobalcalc

isopear=True

calc.append(v.get())if sign == '+':

calc.append('+')

elif sign== '-':

calc.append('-')

elif sign== '*':

calc.append('*')

elif sign== '/':

calc.append('/')

print(calc)

def equal():globalcalc

#获取当前界面的数值准备运算

calc.append(v.get())

print(calc)

#组成运算字符串

calcstr= ''.join(calc)

#检测最后一位是否是运算符,是就删除if calcstr[-1] in '+-*/':

calcstr= calcstr[0:-1]

#print(calcstr)

#运算操作

result=eval(calcstr)

#显示结果

v.set(result)

calc.clear()

#删除操作

def delete():if v.get() == '' or v.get() == '0':

v.set('0')return

else:

num= len(v.get())if num > 1:

strnum= v.get()

strnum= strnum[0:num-1]

v.set(strnum)else:

v.set('0')

#清空操作

def clear():globalcalc

calc=[]

v.set('0')

isopear=False

#正负操作

def fan():

strnum= v.get()if strnum[0] == '-':

v.set(strnum[1:])

elif strnum[0] != '-' and strnum != '0':

v.set('-'+strnum)

#按键区域

frame_bord= Frame(width=400,height=350,bg='#cccccc')

button_del= Button(frame_bord,text = '←',width = 5,height =1,command = delete).grid(row = 0,column = 0)

button_clear= Button(frame_bord,text = 'C',width = 5,height =1,command = clear).grid(row = 0,column = 1)

button_fan= Button(frame_bord,text = '±',width = 5,height =1,command = fan).grid(row = 0,column = 2)

button_ce= Button(frame_bord,text = 'CE',width = 5,height =1,command = clear).grid(row = 0,column = 3)

button_1= Button(frame_bord,text = '1',width = 5,height =2,command = lambda:change('1')).grid(row = 1,column = 0)

button_2= Button(frame_bord,text = '2',width = 5,height =2,command = lambda:change('2')).grid(row = 1,column = 1)

button_3= Button(frame_bord,text = '3',width = 5,height =2,command = lambda:change('3')).grid(row = 1,column = 2)

button_jia= Button(frame_bord,text = '+',width = 5,height =2,command = lambda:operation('+')).grid(row = 1,column = 3)

button_4= Button(frame_bord,text = '4',width = 5,height =2,command = lambda:change('4')).grid(row = 2,column = 0)

button_5= Button(frame_bord,text = '5',width = 5,height =2,command = lambda:change('5')).grid(row = 2,column = 1)

button_6= Button(frame_bord,text = '6',width = 5,height =2,command = lambda:change('6')).grid(row = 2,column = 2)

button_jian= Button(frame_bord,text = '-',width = 5,height =2,command = lambda:operation('-')).grid(row = 2,column = 3)

button_7= Button(frame_bord,text = '7',width = 5,height =2,command = lambda:change('7')).grid(row = 3,column = 0)

button_8= Button(frame_bord,text = '8',width = 5,height =2,command = lambda:change('8')).grid(row = 3,column = 1)

button_9= Button(frame_bord,text = '9',width = 5,height =2,command = lambda:change('9')).grid(row = 3,column = 2)

button_cheng= Button(frame_bord,text = 'x',width = 5,height =2,command = lambda:operation('*')).grid(row = 3,column = 3)

button_0= Button(frame_bord,text = '0',width = 5,height =2,command = lambda:change('0')).grid(row = 4,column = 0)

button_dian= Button(frame_bord,text = '.',width = 5,height =2,command = lambda:change('.')).grid(row = 4,column = 1)

button_deng= Button(frame_bord,text = '=',width = 5,height =2,command = equal).grid(row = 4,column = 2)

button_chu= Button(frame_bord,text = '/',width = 5,height =2,command = lambda:operation('/')).grid(row = 4,column = 3)

frame_bord.pack(padx= 10,pady = 10)

root.mainloop()

服务端: 服务端程序启动之后弹出窗口,管理员输入IP、端口等信息之后点击启动按钮,服务器启动,服务端窗口自动关闭,之后跳转至服务端信息展示界面,包含用户上线提醒,用户发送信息记录展示。 客户端: 客户端程序启动之后,需要弹出登录界面,当用户成功输入昵称、密码、端口、IP等信息(考虑到用户权限问题,本程序在后台默认有固定IP、端口,)用户只需输入昵称、密码(密码用于后期连接数据库时用来匹配数据库存储的用户信息)。当用户成功输入用户名。昵称、密码等信息客户端登录成功跳转至用户进行端对端的聊天界面。聊天界面大致分为聊天记录展示界面,在线好友信息界面以及用户发送信息处。用户在发送消息处输入想要发送的文本消息,选择在线好友中的好友昵称点击选择好友即可选中您要发给的好友昵称,然后点击发送按钮,即可将消息发送给所选择的好友,同时将信息展示在自己的聊天界面中的聊天记录处 2.2. 功能要求 §2.2.1服务端功能要求: 当管理员输入服务器IP、以及端口等信息之后点击启动按钮之后,服务端正常启动之后,需要保持一直开机状态满足所有用户不论在何时登录之后都能进行与好友之间的聊天交流等,同时服务端还要满足监控用户登录信息,不同用户登录客户端之后,服务器后台能够看到某某客户上线了等提示信息。用于服务端查看好友在线状态同时作为服务器,还要能够监控用户的聊天记录,用于监控用户不能发送一些不利言论,从而将其用户及时作封号处理。阻止其传播一些不健康的言论。 §2.2.2客户端要求: 用户在登录界面输入昵称、密码等信息之后成功登录之后,进行窗口之间的跳转,由登录窗口跳转至进行用户之间的聊天窗口,之前的登录窗口也要随之消失。在聊天窗口之中用户需要根据好友在线信息情况选择自己想要与其进行聊天的对象。用户点击在线好友的昵称点击选择好友即可向该好友发送信息,发送成功之后同时要将其发送的信息以及时间信息展示在自己的窗口之中,同时也要在指定好友的窗口之中有所显示以及时间信息
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值