簡體   English   中英

Python Tkinter 用於循環創建和更新的輸入框

[英]Python Tkinter Entry Box For Loop creation and Updation

我使用 for 循環創建了一個 tkinter GUI。 它有一些標簽、輸入框和 2 個按鈕。 一個按鈕拉出輸入框中輸入的任何內容,第二個按鈕根據列表填充輸入框。 第一個按鈕工作正常,但第二個按鈕(FETCH 按鈕)給出此錯誤“ Entry' object has no attribute 'set' ”。 有人可以幫助確認我做錯了什么嗎?

下面是代碼

from tkinter import *

bg_color_2 = "#d9ffff"
background_color = bg_color_2 
button_color = "#ffe08a"
white_font_color = "##ffffff"
black_font_color = "000000"
relief_type = "ridge"

width_of_window = 938
height_of_window = 833

root = Tk()
root.configure(bg= background_color)

screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()

x_coordinate = (screen_width/2) - (width_of_window/2)
y_coordinate = (screen_height/2) - (height_of_window/2)

root.geometry("%dx%d+%d+%d" % (width_of_window, height_of_window, x_coordinate, y_coordinate))

def send():
    rule_entry = []
    for entries in my_entries:
        rule_entry.append(entries.get())

def fetch():
    rule_label_list = ['test1', 'test2', 'test3', 'test4', 'test5', 'test5', 'test6', 'test7', 'test8', 'test9', 'test10', 'test11', 'test12', 'test13', 'test14', 'test15', 'test16', 'test17', 'test18']
    i = 0
    print(my_entries)
    for a in my_entries:
        a.set(rule_label_list[i])
        i + i + 1

root.title("Result Rule")
root.minsize(width_of_window, height_of_window)
root.maxsize(width_of_window, height_of_window)

rule_label_list = ['label1', 'label2', 'label3', 'label4', 'label5', 'label5', 'label6', 'label7', 'label8', 'label9', 'label10', 'label11', 'label12', 'label13', 'label14', 'label15', 'label16', 'label17', 'label18']
my_entries = []
for a in range(0,19):
    my_label = Label(root, text=rule_label_list[a], fg= 'black', bg= bg_color_2, justify = LEFT, width=15,font=("bold", 10), anchor=W, borderwidth = 2)
    my_label.grid(row=a, column=0, pady=5, padx=5)

    my_entry_box = Entry(root, fg= 'black', bg='#FFFFFF', justify = LEFT, width=65,font=("bold", 10))
    my_entry_box.grid(row=a, column=1, columnspan = 4, pady=5)

    my_entries.append(my_entry_box)

Button(root, text='SEND', bg='#ffc200',fg='black', font=("bold", 10), width=15, height = 1,command = send).grid(row=20,column=0,pady=5, padx=5)
Button(root, text='FETCH', bg='#ffc200',fg='black', font=("bold", 10), width=15, height = 1,command = fetch).grid(row=20,column=1,pady=5, padx=5)

root.mainloop()
a = DoubleVar()
a.set(rule_label_list[i])

嘗試在第 34 行添加 DoubleVar。它幫助了我

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM