gpt4 book ai didi

python - Tkinter 常规语句不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 06:07:48 26 4
gpt4 key购买 nike

所以我一直在研究这个非常简单的聊天程序,但无论我做什么,我似乎都无法让它正常工作。由于某种原因,像“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()

`

最佳答案

你需要 GUI.DISABLED 因为 DISABLEDtkinter 命名空间的一部分并且你有:

import tkinter as GUI

同样适用于NEWSNORMAL , END -- GUI.N, GUI.E, ...

关于python - Tkinter 常规语句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20964983/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com