使用Tkinter(py2.7)text文本框中輸入內容在界面中顯示?C較為規整的代碼:
import Tkinter as tk
class Window:
def __init__(self,handle):
self.win = handle
self.createwindow()
self.run()
def createwindow(self):
self.win.geometry('400x400')
#label 1
self.label_text = tk.StringVar()
self.label_text.set("----")
self.lable = tk.Label(self.win,
textvariable=self.label_text,
font=('Arial',11),width=15,height=2)
self.lable.pack()
#text_contrl
self.entry_text = tk.StringVar()
self.entry = tk.Entry(self.win,textvariable=self.entry_text,width=30)
self.entry.pack()
#button
self.button =tk.Button(self.win,text="set label to text",width=15,height=2,command=self.setlabel)
self.button.pack()
def setlabel(self):
print(self.entry_text.get())
self.label_text.set(self.entry_text.get())
def run(self):
try:
self.win.mainloop()
except Exception as e:
print ("*** exception:\n".format(e))
def main():
window = tk.Tk()
window.title('hello tkinter')
Window(window).run()
if __name__ == "__main__":
main()
以上這篇Python-Tkinter Text輸入內容在界面顯示的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

