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

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

如果我添加滾動(dòng)條,所有標(biāo)簽都會(huì)消失

如果我添加滾動(dòng)條,所有標(biāo)簽都會(huì)消失

白豬掌柜的 2023-06-27 17:36:40
在我的程序中,我想添加很多標(biāo)簽,并且要查看所有標(biāo)簽,它們需要滾動(dòng)條。如果我在代碼中添加滾動(dòng)條,那么所有標(biāo)簽都會(huì)消失。我對(duì)長(zhǎng)代碼表示歉意,由于某種原因,如果沒(méi)有所有額外的代碼,我就無(wú)法讓它工作。沒(méi)有滾動(dòng)條的代碼:from tkinter import *from functools import partialwords = ["test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test"]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)#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()帶滾動(dòng)條的代碼:from tkinter import *from functools import partialwords = ["test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test"]def validateLogin(password):    print(password.get())    if password.get() == "test":        newWindow = Tk()        newWindow.geometry('1800x800')        newWindow.title("Passwords")        scrollbar = Scrollbar(newWindow)        scrollbar.pack(side=RIGHT, fill=Y)        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)
查看完整描述

1 回答

?
瀟湘沐

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

我在這里看到兩個(gè)問(wèn)題,第一個(gè)問(wèn)題是您嘗試用于.grid顯示文本的標(biāo)簽,并用于.pack滾動(dòng)條。您不能在同一窗口中同時(shí)使用.grid和。.pack


.grid(row=index, column=0)這是我通過(guò)替換來(lái)糾正此問(wèn)題的代碼.pack(anchor = W)


from tkinter import *

from functools import partial



words = ["test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test"]

def validateLogin(password):

? ? print(password.get())

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

? ? ? ? newWindow = Tk()

? ? ? ? newWindow.geometry('1800x800')

? ? ? ? newWindow.title("Passwords")

? ? ? ? scrollbar = Scrollbar(newWindow)

? ? ? ? scrollbar.pack(side=RIGHT, fill=Y)

? ? ? ? tkWindow.destroy()

? ? ? ? for index, word in enumerate(words):

? ? ? ? ? ? Label(newWindow, text=word).pack(anchor = W)


? ? 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()

第二個(gè)問(wèn)題是滾動(dòng)條實(shí)際上沒(méi)有用。我不相信滾動(dòng)條本身就可以在 tkinter 中的窗口/框架上工作。這意味著修復(fù)原始問(wèn)題后,標(biāo)簽和滾動(dòng)條現(xiàn)在都會(huì)加載,但滾動(dòng)條不會(huì)執(zhí)行任何操作。

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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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