开发者

Tkinter Toplevel Widget

开发者 https://www.devze.com 2023-01-24 08:04 出处:网络
def WhoisWin(): win1 = Toplevel() win1.title(\"Whois\") win1.config(bg=\"black\") win1.geometry(\"300x300\")
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)

This is just a child window that will popup when you click on the menu, I don't get any errors, but Text and Tex1 is not visible on the child window开发者_如何学JAVA, but when I run this code on its own root window it works just find, maybe the ident is messed up or something? Any help will be appreciated, Thanks.


You don't provide a parent for text or text1. When you call Text() you need to give it an argument like Text(win1) or Text(frame) so that Tkinter knows what to pack the Text widget on.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号