第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Tkinter - 創(chuàng)建動(dòng)態(tài)條目小部件

Tkinter - 創(chuàng)建動(dòng)態(tài)條目小部件

精慕HU 2023-06-06 16:24:35
我找不到以下問題的解決方案。a給定的是一個(gè)帶有 4 個(gè)入口小部件, b, c,的 tkinter 應(yīng)用程序,d它必須滿足以下條件:條目中只能輸入數(shù)字a,且不得超過 4 位數(shù)字如果a為空則無法在 中進(jìn)行輸入c。c和的內(nèi)容d與 相同b。如果a不為空,則可以在 中進(jìn)行輸入c。c和的內(nèi)容d相同(它們與 未鏈接b)。當(dāng)前的解決方案僅部分起作用。它能夠鏈接條目b和c取消鏈接它們。但我不知道如何包含 3 條件。from tkinter import *root = Tk()root.geometry("200x200")def only_numeric_input(P):    if len(P) > 0 and P.isdigit():        # enable entry_c and unlink its content from entry_b        entry_c.config(textvariable=" ", state='normal')    else:        # disable entry_c        entry_c.config(textvariable=var_b, state='disabled')    if len(P) > 4:        return False    # checks if entry's value is an integer or empty and returns an appropriate boolean    if P.isdigit() or P == "":  # if a digit was entered or nothing was entered        return True    return Falsecallback = root.register(only_numeric_input)  # registers a Tcl to Python callbackvar_b = StringVar()var_c = StringVar()Label(root, text="a").grid(row = 0, column = 0, pady = (10,0))Label(root, text="b").grid(row = 1, column = 0)Label(root, text="c").grid(row = 2, column = 0)Label(root, text="d").grid(row = 3, column = 0, pady = (40,0))entry_a = Entry(root)entry_b = Entry(root, textvariable = var_b)entry_c = Entry(root, textvariable = var_b, state = "disabled")entry_d = Entry(root, textvariable = var_b)#display entrysentry_a.grid(row = 0, column = 1)entry_b.grid(row = 1, column = 1)entry_c.grid(row = 2, column = 1)entry_d.grid(row = 3, column = 1, pady = (40,0))entry_a.configure(validate="key", validatecommand=(callback, "%P"))  # enables validationmainloop()
查看完整描述

1 回答

?
繁星點(diǎn)點(diǎn)滴滴

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊

給你。您正在使用isdigitfor Pbut%P是整個(gè)文本(包括剛剛按下的內(nèi)容),所以我們切換到isnumeric. 如果我正確理解了你的指示,你就忘了處理entry_d.


我用 arange而不是len(P) > 0 and len(P) < 5,而且range是正確的。


def only_numeric_input(P):

    if len(P) in range(1,5) and P.isnumeric():

        #if we have 1 to 4 numeric characters

        # enable entry_c, and unlink entry c & d content from entry b

        entry_c.config(textvariable=var_c, state='normal')

        entry_d.config(textvariable=var_c)

    elif not P:

        #if we have no characters

        # disable entry_c, and link entry c & d content to entry b

        entry_c.config(textvariable=var_b, state='disabled')

        entry_d.config(textvariable=var_b)

    else:

        #everything else

        return False

    

    return True


查看完整回答
反對(duì) 回復(fù) 2023-06-06
  • 1 回答
  • 0 關(guān)注
  • 172 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)