python3 tkinter 擷取輸入字串長度

來源:互聯網
上載者:User

標籤:port   label   stringvar   enum   strip()   擷取   str   inf   var   

 

python 3  擷取輸入字元長度

 

 

#-*- coding:utf-8 -*-from tkinter import *from tkinter import messageboxdef get_Tk():    top = Tk()    return top#定義擷取字元長度函數def sum_test(baseNum):    return len(baseNum)def show_result(top,re_sum):    #這裡使用Toplevel(top) 是為了新開一個視窗 ,且顯示計算結果,如果直接執行個體化一個視窗,則新視窗不顯示結算結果。    top_show = Toplevel(top)    top_show.title("字元長度顯示")    top_show.geometry(‘300x240+810+420‘)    # 顯示長度    Sums = Label(top_show, text=‘字元長度:‘)    Sums.pack()    sum_text = StringVar()    sums = Entry(top_show, textvariable=sum_text,state=‘readonly‘)    sum_text.set(re_sum)    sums.pack()    top_show.mainloop()def on_click(top,base_text):    #擷取輸入資訊    if base_text.get().strip() == ‘‘:        messagebox.showinfo(title=‘字串‘, message=‘字元為空白,請輸入有效數值!‘)    else:        base_Num = base_text.get()    strlen = sum_test(base_Num)    show_result(top,strlen)def put_info():    top = get_Tk()    #top.minsize(100, 100)  # 視窗的最小縮放    top.title("輸入字串")    top.geometry(‘300x240+420+420‘)    baseNum = Label(top, text=‘字串:‘)    baseNum.pack()    base_text = StringVar()    base = Entry(top, textvariable=base_text)    base_text.set(" ")    base.pack()    Button(top, text="計算", command= lambda:on_click(top,base_text)).pack()    top.mainloop()   # 這種 直接command = 方法名的方式,函數是不能傳遞參數的,所以為了能傳遞參數使用了上面的方法。   # Button(top, text="計算", command= on_click).pack()if __name__ == ‘__main__‘:    put_info()

 

python3 tkinter 擷取輸入字串長度

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.