所以我一直在这个非常简单的聊天程序工作,但不管我做什么,我似乎无法让它正常工作。由于某种原因,诸如“state = DISABLED”和“sticky = N + S + E + W”之类的常规语句不再有效,只是导致以下错误:
Traceback (most recent call last):
File "C:\Users\K2\Desktop\Projekt 1\chWin.py", line 60, in <module>
chWin = chWin()
File "C:\Users\K2\Desktop\Projekt 1\chWin.py", line 12, in __init__
self.chatWin.configure( bg = '#747371', fg = 'orange', state = DISABLED )
NameError: global name 'DISABLED' is not defined
我真的没有想法,无法在任何地方找到答案。也许这很简单,不知道!请帮忙! `
import tkinter as GUI
switch = False
class chWin( GUI.Tk ):
def __init__( self ):
GUI.Tk.__init__( self )
#Medalandefönster
self.chatWin = GUI.Text( self )
self.chatWin.configure( bg = '#747371', fg = 'orange', state = DISABLED )
self.chatWin.grid( row = 0, column = 0, sticky = N+S+E+W)
#Scrollbaren
self.scrl = GUI.Scrollbar(self)
self.scrl.grid( row = 0, column = 0, sticky = N+S+E+W)
#Gör så att scrollbar fungerar
self.scrl.configure( command = self.chatWin.yview)
self.chatWin.configure( yscrollcommand = self.scrl.set, state = DISABLED )
#Medalandeinput
self.msg = GUI.Entry( self )
self.msg.configure( bg = '#262626', fg = 'orange' )
self.msg.grid( row = 1, sticky = N+S+E+W)
#Skicka-knapp
self.btn = GUI.Button( self, text = '<< Send >>', command = self.sendMsg )
self.btn.configure( bg = 'orange', fg = 'black' )
self.btn.bind('<Button-1>', self.sendMsg)
self.btn.grid( row = 1, sticky = N+S+E+W)
#Binder "Enter" till knappen
self.msg.bind('<Return>', self.sendMsg )
def sendMsg(self, event=None):
global switch
send = self.msg.get()
print (send)
if len(send) < 1:
pass
else:
ext = 'Me:\n '
ext = ext + send
self.chatWin.configure(state = NORMAL)
self.chatWin.insert(END, ext + '\n')
self.chatWin.yview(END)
self.chatWin.configure(state = DISABLED)
sak = ext + '\n'
switch = True
while switch == True:
mess = send.encode()
s.send(mess)
print('client sent: ', mess)
switch = False
msg.delete(0, END)
chWin = chWin()
chWin.mainloop()
`
答案 0 :(得分:1)
您需要GUI.DISABLED
,因为DISABLED
是tkinter
命名空间的一部分,您有:
import tkinter as GUI
同样适用于N
,E
,W
,S
,NORMAL
,END
- GUI.N
,{ {1}},...