我想请你帮忙。
我正在尝试清除一个框架,然后在其中添加新元素。但是,清除所有元素后,添加新元素不显示。能否请您对我的问题有所了解。谢谢
这是我的代码
#!/usr/bin/env python
import Tkinter as tk
import socket
import sys
def next(line, num):
s.send(line)
data= s.recv(size)
num.set(data)
class Client(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid()
self.configHost()
def configHost(self):
self.hostEntry = tk.Entry(self, justify=tk.CENTER);
self.hostLabel = tk.Label(self, text='Host')
self.connectButton = tk.Button(self, text='Connect', command=lambda:self.startServe())
self.hostLabel.grid(row=0, column=0, ipadx=10, ipady=10)
self.hostEntry.grid(row=0, column=1, columnspan=4, pady=20, padx=20, ipadx=5, ipady=5)
self.connectButton.grid(column=2,pady=10)
def startServe(self):
hostnum = self.hostEntry.get()
port = 50000
size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((hostnum,port))
if s >= 0:
self.grid_forget()
tk.Frame.__init__(self, master=None)
self.grid()
self.nowServingLabel= tk.Label(self, text="Sample")
self.button = tk.Button(self, text='Connect')
self.nowServingLabel.grid()
self.button.grid()