私は現在、このコードをユーザから受け取り、入力されたボタンの量を生成します。そして、各ボタンが送信可能なフィールドを持つことを望みます。変数として戻って、しかし、以下のコードは何らかの理由でテキストフィールドの値を受け取っていませんが、同じ方法でそれを試してみましたが...私は何かを見逃してしまったのですか?方法?Python Tkinterは1つをマッチさせるのではなくランダムな入力を返します
(私はPython tkinter creating buttons in for loop passing command argumentsを使用しようとしましたが、何らかの理由で入力から文字列を返すときに、それらを混ぜて返します。例えば、4の代わりにテキスト入力フィールド3の値を返します。 )
from tkinter import *
from random import randint
inputValue = randint(3, 9)
root = Tk()
def retrieve_input2(inputed):
global buttons # get the dict
global Texts # get the dict
Texts.reverse()
print(inputed) # print what number button was pressed
inputed = int(inputed) - 1
inputvalue2 = Texts[inputed].get("1.0", "end-1c") # get the inputted value corresponding to button pressed
print(inputvalue2) # print the value that was entered
buttons = [] # create empty dicts
Texts = [] # create empty dicts
while inputValue > 0: # for every number in inputted value
parse = str(inputValue) # create a string version of the input value that can be parsed to the retrieve function
button = Button(root, text="Lap :" + str(inputValue), command=lambda parse = parse: retrieve_input2(parse)) # create button variable
Texti = Text(root, height=1, width=5) # Create Text Variable
button.grid(row=inputValue, column=1) # put the button on the gui
Texti.grid(row=inputValue, column=0,) # Put the field on the gui
Texts.append(Texti) # append Value to dict
buttons.append(button) # append Value to dict
inputValue = int(inputValue) - 1 # take one
root.mainloop() # Does work (required)
おかげで、そのので、代わりにキー例えば「1」、値prinitingと呼ばれる辞書の「NewDictを[button_num = inputvalue2]」追加seccond辞書を作成する必要がありました:」テキスト1' 、テキストを入力された '1': 'Kieron' – ItzKmaf