passenden I derzeit dieses Stück Code haben, der eine Eingabe von einem Benutzer nehmen und die eingegebene Menge an Tasten erzeugen, i dann für jede Taste wünschen, ein Feld zu haben, die gesendet werden können, zurück als Variable jedoch der folgende Code aus irgendeinem Grunde nicht den Wert des Textfeldes erhält, obwohl, wenn ich es auf die gleiche Weise versucht, mit einem es funktioniert ... Habe ich etwas verpaßt oder bin ich dies gehe über die falschen Weg? (Zufälliger Eingabewert zur Simulation der Benutzereingabe)Python Tkinter Zufallseingänge liefert statt einen
(Ich habe versucht, Python tkinter creating buttons in for loop passing command arguments, aber dies aus irgendeinem Grund beim Zurückgeben der Strings von der Eingabe, mischt sie auch z. B. gibt den Wert von Texteingabefeld 3 statt 4 )
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)
Danke, Hatte ein seccond Wörterbuch zu erstellen, die fügt hinzu 'newDict [button_num = inputvalue2]', so dass anstelle des dict wenn priniting den Schlüssel zB genannt '1' dann wird der Wert:‘text1' , der Text eingegeben wird so '1' gedruckt: 'Kieron' – ItzKmaf