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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

python-entry widget 位置更改不會發(fā)生并且標簽創(chuàng)建問題

python-entry widget 位置更改不會發(fā)生并且標簽創(chuàng)建問題

湖上湖 2023-07-18 16:41:01
代碼如下所示,但未重新定位條目小部件位置,也未創(chuàng)建標簽。在輸入此代碼之前 [ e1.grid(row=1,column=1) ] 程序工作正常,輸入代碼后不工作,如何處理這個問題..該程序是try :import tkinter as tk # Python 3except :import Tkinter as tk # Python 2def update_sum() :# Sets the sum of values of e1 and e2 as val of e3try :    sum_tk.set((float(e1_tk.get().replace(' ', '')) + float(e2_tk.get().replace(' ', ''))))except :    passroot.after(10, update_sum) # reschedule the eventreturnroot = tk.Tk()root.geometry('850x450')e1_tk = tk.StringVar(root) # Initializes a text variable of tk to use to get e1's val.e2_tk = tk.StringVar(root) # Initializes a text variable of tk to use to get e2's val.sum_tk = tk.StringVar(root) # Initializes a text variable of tk to use to set e3's val.# Entriese1 = tk.Entry(root, textvariable = e1_tk)e1.grid(row=1,column=1)e2 = tk.Entry(root, textvariable = e2_tk)e2.grid(row=1,column=2)e3 = tk.Entry(root, textvariable = sum_tk)e3.grid(row=1,column=3)e1=Label(root,text="SL")e1.grid(row=1,column=0)e1.pack()e2.pack()e3.pack()# Will update the sum every second 10 ms = 0.01 second it takes ms as arg.root.after(10, update_sum)root.mainloop()提前致謝..
查看完整描述

1 回答

?
慕少森

TA貢獻2019條經(jīng)驗 獲得超9個贊

您對 2 個小部件使用相同的變量并在其上使用網(wǎng)格函數(shù)


Grid 和 pack 是兩個內(nèi)置布局管理器,包括 place


我們只能在單個元素上使用其中之一


在您的程序中,您正在打包e1、e2、e3并嘗試為它們提供網(wǎng)格布局。


此外,您還使用了e1.grid()兩次不同的列值。


try :

    import tkinter as tk # Python 3

except :

    import Tkinter as tk # Python 2


def update_sum() :

# Sets the sum of values of e1 and e2 as val of e3

    try :

        sum_tk.set((float(e1_tk.get().replace(' ', '')) + float(e2_tk.get().replace(' ', ''))))

    except :

        pass


    root.after(10, update_sum) # reschedule the event

    return


root = tk.Tk()

root.geometry('850x450')


e1_tk = tk.StringVar(root) # Initializes a text variable of tk to use to get e1's val.

e2_tk = tk.StringVar(root) # Initializes a text variable of tk to use to get e2's val.

sum_tk = tk.StringVar(root) # Initializes a text variable of tk to use to set e3's val.


# Entries

e1 = tk.Entry(root, textvariable = e1_tk)

e1.grid(row=1,column=1)

e2 = tk.Entry(root, textvariable = e2_tk)

e2.grid(row=1,column=2)

e3 = tk.Entry(root, textvariable = sum_tk)

e3.grid(row=1,column=3)


e4=tk.Label(root,text="SL")

e4.grid(row=1,column=0)




# Will update the sum every second 10 ms = 0.01 second it takes ms as arg.

root.after(10, update_sum)

root.mainloop()


查看完整回答
反對 回復 2023-07-18
  • 1 回答
  • 0 關注
  • 100 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號