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

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

添加大量標(biāo)簽的更好方法

添加大量標(biāo)簽的更好方法

慕村9548890 2023-06-20 16:22:49
我正在嘗試在 tkinter 的窗口中添加大量文本,我希望它們排成一行。我可以用比我現(xiàn)在做的更簡單的方式來做嗎,因?yàn)槊看味疾粩嗵砑訕?biāo)簽和更改行真的很煩人。(“bingbong”只是一個(gè)例子,我將連續(xù)使用不同的密碼而不是那些 bingbong。)from tkinter import *from functools import partialdef validateLogin(password):    print(password.get())    if password.get() == "test":        newWindow = Tk()        newWindow.geometry('1800x800')        newWindow.title("Passwords")        tkWindow.destroy()        Label(newWindow, text="bingbong").grid(row=1, column=0)        Label(newWindow, text="bingbong").grid(row=2, column=0)        Label(newWindow, text="bingbong").grid(row=3, column=0)        Label(newWindow, text="bingbong").grid(row=4, column=0)        Label(newWindow, text="bingbong").grid(row=5, column=0)        Label(newWindow, text="bingbong").grid(row=6, column=0)        Label(newWindow, text="bingbong").grid(row=7, column=0)        Label(newWindow, text="bingbong").grid(row=8, column=0)    if password.get() != "test":        Label(tkWindow, text="Wrong password!", fg='red').grid(row=5, column=2)#windowtkWindow = Tk()tkWindow.geometry('250x100')tkWindow.title('Passwords')#password label and password entry boxpasswordLabel = Label(tkWindow,text="Password").grid(row=1, column=0)password = StringVar()passwordEntry = Entry(tkWindow, textvariable=password, show='*').grid(row=1, column=2)validateLogin = partial(validateLogin, password)#login buttonloginButton = Button(tkWindow, text="Login", command=validateLogin).grid(row=4, column=2)tkWindow.mainloop()
查看完整描述

1 回答

?
呼如林

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

使用循環(huán)來創(chuàng)建它們,而不是一次一個(gè)地手動(dòng)創(chuàng)建它們


from tkinter import *

from functools import partial



words = ["foo", "bar", "baz", "bingbong", "foobar", "foobaz", "foofoo", "barbar"]

def validateLogin(password):

    print(password.get())

    if password.get() == "test":

        newWindow = Tk()

        newWindow.geometry('1800x800')

        newWindow.title("Passwords")

        tkWindow.destroy()

        for index, word in enumerate(words):

            Label(newWindow, text=word).grid(row=index, column=0)


    if password.get() != "test":

        Label(tkWindow, text="Wrong password!", fg='red').grid(row=5, column=2)


#window

tkWindow = Tk()

tkWindow.geometry('250x100')

tkWindow.title('Passwords')


#password label and password entry box

passwordLabel = Label(tkWindow,text="Password").grid(row=1, column=0)

password = StringVar()

passwordEntry = Entry(tkWindow, textvariable=password, show='*').grid(row=1, column=2)


validateLogin = partial(validateLogin, password)


#login button

loginButton = Button(tkWindow, text="Login", command=validateLogin).grid(row=4, column=2)


tkWindow.mainloop()

編輯:使用枚舉函數(shù)同時(shí)訪問字符串值(本例中為密碼)和索引


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

添加回答

舉報(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)