window = tk.Tk()
t = tk.Text(window2, height=15, width=65)
button = tk.Button(window,text='获 取 IP', command=getIP,width=15, height=2)
def getIP():
IP = t.insert('end',randomIP())
运行以后是这样的:

很显然,ip地址粘在一起了,如果我们要每读取一次ip就换行一次,那只需要加入语句:t.insert(tk.INSERT, '\n')
即可
如下所示:
window = tk.Tk()
t = tk.Text(window2, height=15, width=65)
button = tk.Button(window,text='获 取 IP', command=getIP,width=15, height=2)
def getIP():
IP = t.insert('end',randomIP())
t.insert(tk.INSERT, '\n')
修改后的效果:

有python代码:window = tk.Tk()t = tk.Text(window2, height=15, width=65)button = tk.Button(window,text='获 取 IP', command=getIP,width=15, height=2)def getIP(): # randomIP()的作用是从数据库获取一个ip地址 IP = t...
win=tkinter.Tk()
text=tkinter.Text(win) #文本编辑器(用于展示数据)
text.insert(tkinter.INSERT,"因为你在我心中是那么的具体")
text.insert(tkinter.INSERT,"\r\n") #换行
text.insert(tkinter.INSERT,"因为你在我心中是那么的具体")
text.insert(tkinter.INSERT,"\r\n")
text.insert(tkinter.INSERT,"因为你在我心中是那么的具体")
text.insert(tki
text = Text(root,width=20,height=15)
text.pack()
text.insert(INSERT,"Python3 \n") #INSERT索引表示插入光标当前的位置
text.insert(END,"python算法")
mainloop()
evalue = e.get()
print 'btn Click and Entry value is %s' % evalue
def btn_click_bind(event):
print 'enter b2'
def show_toplevel():
top = Toplevel()
文章目录文字区域Text 的基本概念文字区域Text 的基本应用插入文字insert()Text 加上滚动条 Scrollbar 设计加上X轴滚动条字形familyweightsize选取文字认识Text 的索引建立书签 Marks
文字区域Text 的基本概念
Entry控件主要是处理单行的文字,Text控件可以视为Entry的扩充,因为它可以处理多行的输入,另外也可以在文字中嵌入图像或是提...
您可以使用Tkinter中的tag_config()方法来设置text控件的文本颜色。例如,您可以使用以下代码将文本颜色设置为红色:
text.tag_config('red', foreground='red')
text.insert('end', '这是红色的文本', 'red')
其中,'red'是标签名称,foreground参数用于设置文本颜色。在插入文本时,将标签名称作为第二个参数传递给insert()方法。