首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tkinter Toplevel小部件

Tkinter Toplevel小部件
EN

Stack Overflow用户
提问于 2010-11-07 09:54:30
回答 1查看 2.7K关注 0票数 0
代码语言:javascript
复制
def WhoisWin():

win1 = Toplevel()
win1.title("Whois")
win1.config(bg="black")
win1.geometry("300x300")
win1.resizable(0,0)

text = Text()
text1 = Text()

text1.config(width=15, height=1)
text1.config(bg="black", fg="white")
text1.pack()

def button1():
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect(("com.whois-servers.net", 43))
            s.send(text1.get("1.0", END) + "\r\n")
            response = ''
            while True:
                a = s.recv(4096)
                response += a
                if a == '':
                   break
            s.close()
            text.insert(END, response)

def clear():
        text.delete("1.0", END)  
        text1.delete("1.0", END)       

frame = Frame(win1)
frame.config(bg="black")
frame.pack(pady=10, padx=5)

b = Button(frame, text="Enter", width=10, height=2, command=button1)
b.config(fg="white", bg="black")
b.pack(side=LEFT, padx=5)

c = Button(frame, text="Clear", width=10, height=2, command=clear)
c.config(fg="white", bg="black")
c.pack(side=RIGHT, padx=5)

scrollbar = Scrollbar(win1)
scrollbar.pack(side=RIGHT, fill=Y)
text.config(width=35, height=15, bg="black", fg="white")
text.pack(side=LEFT, fill=Y)
scrollbar.config(command=text.yview)
text.config(yscrollcommand=scrollbar.set)

这只是一个子窗口,当你点击菜单时它会弹出,我没有得到任何错误,但是文本和Tex1在子窗口上是不可见的,但当我在它自己的根窗口上运行这段代码时,它只是找到,可能是标识搞乱了什么?任何帮助都将不胜感激,谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-11-07 09:57:07

您不需要为texttext1提供父级。当你调用Text()时,你需要给它一个像Text(win1)Text(frame)这样的参数,这样Tkinter才能知道要把文本小部件打包到什么地方。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4116157

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档