Code: Alles auswählen
from tkinter import *
y = 2
x = 4
previous_button_id = None
def addBox():
global y
asset_label2 = Label(root, text='Asset: ')
asset_entry2 = Entry(root)
ticker_label2 = Label(root, text='Ticker: ')
ticker_entry2 = Entry(root)
percent_label2 = Label(root, text='Prozentualer Anteil: ')
percent_entry2 = Entry(root)
asset_label2.grid(row=y, column=0)
asset_entry2.grid(row=y, column=1)
ticker_label2.grid(row=y, column=2)
ticker_entry2.grid(row=y, column=3)
percent_label2.grid(row=y+1, column=2)
percent_entry2.grid(row=y+1, column=3)
addboxButton.grid(row=y+1)
global addbox2button2
addbox2button2 = Button(root, text='+', command=lambda: addBox2(addbox2button2), height=1, width=2)
addbox2button2.grid(row=y, column=4, padx=3, sticky='w')
y += 2
def addBox2(button_id):
global x
global previous_button_id
ticker_label3 = Label(root, text='Ticker: ')
ticker_entry3 = Entry(root)
percent_label3 = Label(root, text='Prozentualer Anteil: ')
percent_entry3 = Entry(root)
if (previous_button_id == None) or (previous_button_id == button_id):
ticker_label3.grid(row=int(button_id.grid_info()['row']), column=x)
if button_id.grid_info()['row'] != 0:
addbox2button2.grid(column=ticker_label3.grid_info()['column']+1, padx=3, sticky='w')
else:
addbox2Button.grid(column=ticker_label3.grid_info()['column']+1, padx=3, sticky='w')
else:
x = 4
ticker_label3.grid(row=int(button_id.grid_info()['row']), column=x)
if button_id.grid_info()['row'] != 0:
addbox2button2.grid(column=ticker_label3.grid_info()['column']+1, padx=3, sticky='w')
else:
addbox2Button.grid(column=ticker_label3.grid_info()['column']+1, padx=3, sticky='w')
previous_button_id = button_id
x +=1
root = Tk()
asset_label = Label(root, text='Asset: ')
ticker_label = Label(root, text='Ticker:')
percent_label= Label(root, text='Prozentualer Anteil:')
asset_entry = Entry(root)
ticker_entry = Entry(root)
percent_entry = Entry(root)
addboxButton = Button(root, text='+', command=addBox, height=1, width=2)
addbox2Button = Button(root, text='+', command=lambda: addBox2(addbox2Button), height=1, width=2, )
asset_label.grid(row=0, column=0)
asset_entry.grid(row=0, column=1)
ticker_label.grid(row=0, column=2)
ticker_entry.grid(row=0, column=3)
percent_label.grid(row=1, column=2)
percent_entry.grid(row=1, column=3)
addboxButton.grid(row=1, column=1, sticky='e')
addbox2Button.grid(row=0, column=4, sticky='w', padx=3, pady=3)
root.mainloop()