I am trying to learn tkinter and got stuck with a little problem. I have created a very simple window that has 2 messages on top "Activity:", "Time Spend:" and a Button "+" on the Bottom of the Window.
from tkinter import *
root = Tk()
root.geometry("274x520+868+240")
root.minsize(120, 1)
root.maxsize(3284, 1068)
root.resizable(0, 0)
root.title("Learning")
root.configure(background="black")
def new_entry():
n = [n for n in range(30, 490, 30)]
for i in n:
e1 = Entry(root)
e2 = Entry(root)
e1.place(y=i, width=133)
e2.place(x=141, y=i, width=137)
print(e1, e2)
return e1, e2
b1 = Button(root)
b1.place(y=499, width=276)
b1.configure(text="+")
b1.configure(command=new_entry)
b1.configure(background="darkgrey")
msg1 = Message(root)
msg1.place(width=133, height=29)
msg1.configure(text="Activity:")
msg1.configure(background="darkgrey")
msg2 = Message(root)
msg2.place(x=141, width=137, height=29)
msg2.configure(text="Time Spend:")
msg2.configure(background="darkgrey")
root.mainloop()
The Button is supposed to create 2 entrys next to each other, every time it is clicked, but if i click the button, it will create the entrys once, clicking it again wont create the entrys on the window, but just creates this in my terminal:
.!entry .!entry2
.!entry3 .!entry4
.!entry5 .!entry6
.!entry7 .!entry8
If I remove the "return e1,e2" statement, all entrys are created in terminal as well as in the window, with 1 click of the button, instead of being created 2 by 2 for every click of the button.
If I remove the "print(e1,e2)" statement, clicking the button will create the 2 entrys only once, and doesnt show anything in the terminal.
New entrys should be created with a little space in between, until the upper border of the Button is reached (in this case 32 Entrys, 16 rows).
Could someone also explain why msg1 is displayed wrong (it is not centered and it is splitted in two lines), but msg2 is fine, they have the same specs??