from
tkinter
import
*
import
tkinter as tk
from
tkinter
import
ttk
import
tkinter.font as tkFont
import
time
import
IDEKuaishou3_kuaishou
import
threading
LOG_LINE_NUM
=
0
CHAT_LINE_NUM
=
0
class
App_Kuaishou:
def
__init__(
self
,root):
self
.InitIDE()
self
.id_list
=
[]
self
.name_list
=
[]
self
.kuaishou
=
IDEKuaishou3_kuaishou.Kuaishou(
self
)
self
.Show_liveroom()
self
.threadStatus
=
False
self
.anchor
=
''
def
InitIDE(
self
):
root.title(
"快手直播-王者荣耀版"
)
width
=
1070
height
=
491
screenwidth
=
root.winfo_screenwidth()
screenheight
=
root.winfo_screenheight()
alignstr
=
'%dx%d+%d+%d'
%
(width, height, (screenwidth
-
width)
/
2
, (screenheight
-
height)
/
2
)
root.geometry(alignstr)
root.resizable(width
=
False
, height
=
False
)
ft
=
tkFont.Font(family
=
'宋体'
, size
=
12
)
GLabel_liveroom
=
tk.Label(root,font
=
ft,fg
=
"#333333"
,justify
=
"center"
, text
=
"直播间"
, relief
=
"flat"
)
GLabel_liveroom.place(x
=
0
, y
=
0
, width
=
51
, height
=
33
)
self
.Combobox_liveroom
=
ttk.Combobox(root, font
=
ft, justify
=
"center"
,state
=
'readonly'
)
self
.Combobox_liveroom.bind(
"<<ComboboxSelected>>"
,
self
.Show_liveroom)
self
.Combobox_liveroom.place(x
=
60
, y
=
0
, width
=
249
, height
=
34
)
self
.GButton_enterroom
=
tk.Button(root,font
=
ft,bg
=
"#efefef"
,fg
=
"#000000"
,text
=
"进房"
,justify
=
"center"
, relief
=
"groove"
,
state
=
DISABLED,command
=
self
.GButton_enterroom_command )
self
.GButton_enterroom.place(x
=
310
, y
=
0
, width
=
87
, height
=
69
)
GLabel_did
=
tk.Label(root,font
=
ft,fg
=
"#333333"
,justify
=
"center"
, text
=
"did"
, relief
=
"flat"
)
GLabel_did.place(x
=
0
, y
=
40
, width
=
43
, height
=
31
)
ft_did
=
tkFont.Font(family
=
'宋体'
, size
=
9
)
self
.GLineEdit_did
=
tk.Entry(root,borderwidth
=
"1px"
,font
=
ft_did,fg
=
"#333333"
,justify
=
"left"
, relief
=
"groove"
)
self
.GLineEdit_did.place(x
=
60
, y
=
40
, width
=
248
, height
=
30
)
GLabel_anchor
=
tk.Label(root,font
=
ft,fg
=
"#333333"
,justify
=
"center"
, text
=
"主播ID"
, relief
=
"flat"
)
GLabel_anchor.place(x
=
0
, y
=
80
, width
=
53
, height
=
30
)
self
.GLineEdit_anchorid
=
tk.Entry(root,borderwidth
=
"1px"
,font
=
ft,fg
=
"#333333"
,justify
=
"left"
, relief
=
"groove"
)
self
.GLineEdit_anchorid.place(x
=
60
, y
=
80
, width
=
148
, height
=
30
)
self
.GButton_disconnet
=
tk.Button(root,font
=
ft,bg
=
"#efefef"
,fg
=
"#000000"
,text
=
"断开"
,justify
=
"center"
, relief
=
"groove"
,
command
=
self
.GButton_disconnet_command )
self
.GButton_disconnet.place(x
=
210
, y
=
80
, width
=
74
, height
=
30
)
ft_onlinenumber
=
tkFont.Font(family
=
'宋体'
, size
=
9
)
self
.GLabel_onlinenumber
=
tk.Label(root,font
=
ft_onlinenumber,fg
=
"#333333"
,justify
=
"center"
, text
=
"在线人数"
, relief
=
"flat"
)
self
.GLabel_onlinenumber.place(x
=
300
, y
=
80
, width
=
99
, height
=
31
)
self
.GLineEdit_inputmsg
=
tk.Entry(root,borderwidth
=
"1px"
,font
=
ft,fg
=
"#333333"
,text
=
"cookie"
,justify
=
"left"
, relief
=
"groove"
)
self
.GLineEdit_inputmsg.place(x
=
0
, y
=
120
, width
=
305
, height
=
30
)
self
.GButton_sendmsg
=
tk.Button(root,font
=
ft,bg
=
"#efefef"
,fg
=
"#000000"
,text
=
"发送"
,justify
=
"center"
, relief
=
"groove"
,
command
=
self
.GButton_sendmsg_command )
self
.GButton_sendmsg.place(x
=
310
, y
=
120
, width
=
85
, height
=
30
)
ft_txt
=
tkFont.Font(family
=
'宋体'
, size
=
10
)
self
.GText_chatlist
=
tk.Text(root,borderwidth
=
"1px"
,font
=
ft_txt,fg
=
"#333333"
, relief
=
"groove"
)
self
.GText_chatlist.place(x
=
400
, y
=
0
, width
=
667
, height
=
484
)
self
.GText_log
=
tk.Text(root,borderwidth
=
"1px"
,font
=
ft_txt,fg
=
"#333333"
, relief
=
"groove"
)
self
.GText_log.place(x
=
0
, y
=
160
, width
=
398
, height
=
326
)
def
GButton_enterroom_command(
self
):
print
(
"GButton_enterroom"
)
self
.write_log_to_Text(
"GButton_enterroom"
)
self
.GButton_enterroom[
'state'
]
=
DISABLED
self
.threadStatus
=
True
self
.write_chat_to_Text(
'~~~~~~~~~~~~~进入[%s]聊天室~~~~~~~~~~~开始获取聊天记录'
%
self
.anchor)
obj1
=
threading.Thread(target
=
self
.kuaishou.EnterRoom, args
=
(
self
.GLineEdit_anchorid.get(),))
obj1.start()
def
GButton_disconnet_command(
self
):
print
(
"弹幕线程终止"
)
self
.threadStatus
=
False
self
.write_log_to_Text(
"弹幕线程终止"
)
self
.GButton_enterroom[
'state'
]
=
ACTIVE
def
GButton_sendmsg_command(
self
):
print
(
"GButton_sendmsg"
)
self
.write_log_to_Text(
"GButton_sendmsg"
)
self
.write_chat_to_Text(
"GButton_sendmsg"
)
def
Show_liveroom(
self
,
*
args):
self
.GLineEdit_anchorid.delete(
0
,END)
self
.GLineEdit_anchorid.insert(
0
,
self
.id_list[
self
.Combobox_liveroom.current()])
self
.anchor
=
self
.name_list[
self
.Combobox_liveroom.current()]
def
write_chat_to_Text(
self
, logmsg):
global
CHAT_LINE_NUM
logmsg_in
=
str
(logmsg)
+
"\n"
if
CHAT_LINE_NUM <
=
24
:
self
.GText_chatlist.insert(END, logmsg_in)
CHAT_LINE_NUM
=
CHAT_LINE_NUM
+
1
ctemp
=
logmsg.split(
':'
)[
0
]
cstart
=
str
(CHAT_LINE_NUM)
+
'.0'
cend
=
str
(CHAT_LINE_NUM)
+
'.'
+
str
(
len
(ctemp))
self
.GText_chatlist.tag_add(
'tag1'
,cstart,cend)
self
.GText_chatlist.tag_config(
'tag1'
,background
=
'lightyellow'
,foreground
=
'red'
,font
=
'黑体 12'
)
cstart
=
str
(CHAT_LINE_NUM)
+
'.'
+
str
(
len
(logmsg)
-
19
)
cend
=
str
(CHAT_LINE_NUM)
+
'.end'
self
.GText_chatlist.tag_add(
'tag2'
,cstart,cend)
self
.GText_chatlist.tag_config(
'tag2'
,foreground
=
'DarkSlateBlue'
,font
=
'黑体 10'
)
else
:
self
.GText_chatlist.delete(
1.0
,
2.0
)
self
.GText_chatlist.insert(END, logmsg_in)
ctemp
=
logmsg.split(
':'
)[
0
]
cstart
=
str
(CHAT_LINE_NUM)
+
'.0'
cend
=
str
(CHAT_LINE_NUM)
+
'.'
+
str
(
len
(ctemp))
self
.GText_chatlist.tag_add(
'tag1'
,cstart,cend)
self
.GText_chatlist.tag_config(
'tag1'
,background
=
'lightyellow'
,foreground
=
'red'
,font
=
'黑体 12'
)
cstart
=
str
(CHAT_LINE_NUM)
+
'.'
+
str
(
len
(logmsg)
-
19
)
cend
=
str
(CHAT_LINE_NUM)
+
'.end'
self
.GText_chatlist.tag_add(
'tag2'
,cstart,cend)
self
.GText_chatlist.tag_config(
'tag2'
,foreground
=
'DarkSlateBlue'
,font
=
'黑体 10'
)
def
get_current_time(
self
):
current_time
=
time.strftime(
'%H:%M:%S'
, time.localtime(time.time()))
return
current_time
def
write_log_to_Text(
self
, logmsg):
global
LOG_LINE_NUM
current_time
=
self
.get_current_time()
logmsg_in
=
str
(current_time)
+
" "
+
str
(logmsg)
+
"\n"
if
LOG_LINE_NUM <
=
20
:
self
.GText_log.insert(END, logmsg_in)
LOG_LINE_NUM
=
LOG_LINE_NUM
+
1
else
:
self
.GText_log.delete(
1.0
,
2.0
)
self
.GText_log.insert(END, logmsg_in)
if
__name__
=
=
"__main__"
:
root
=
tk.Tk()
app
=
App_Kuaishou(root)
root.mainloop()