1

I got a canvas field and need a text input box, but I don't find a working solution. There is an entry field now but center North and I need this entry field on the left site and i don't know how to position this entry field.

GUI = Tk()
GUI.configure(background="#002E52")
GUI.title('Templatewriter')
GUI.geometry("1920x1080")
e = Entry(GUI)
e.pack()
e.delete(0, END)
e.insert(0, "Überschrift eingeben")
box2 = Canvas(GUI, width=200, height=50)
box2.pack()
box2.place(x=0, y=0)
box2.create_text((50, 25), text="Überschrift 1 ", fill="black")
linie = Canvas(GUI, width=10, height=1080)
linie.pack()
box1 = Canvas(GUI, width=1920, height=1080)
box1.pack()
GUI.mainloop()

Is there anyway to do it?

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • In using `pack()` you can provide a side. so `pack(side="left")` might help however I would prefer to use `grid()` here. I think it would make things easier to manager on the layout. – Mike - SMT Mar 21 '18 at 14:26
  • It is not clear what you are trying to accomplish here. What is the goal of your program? – Mike - SMT Mar 21 '18 at 14:32
  • Don't use pack and place on box2. Stick to one or the other. –  Mar 21 '18 at 14:52

1 Answers1

0

Try not to mix different layout managers, it becomes messy.

Instead of packing, use the grid() or place() method. Since the layout in your program is simple, it would be more efficient to use grid().

object = Canvas(GUI, etc.)
object.grid(row = 1, column = 1)

The grid method works like battleship. You specify the row and column, and the objects are placed there.

The place() method is more precise (You already have it in use). I would recommend using this throughout the program if there are specific measurements.

object = Canvas(GUI, etc.)
object.place(x = 30, y = 50)

Additional info here: http://zetcode.com/gui/tkinter/layout/

Rohan
  • 543
  • 6
  • 14
  • Thanks for your answer ! I Used the Canvas for the little line in the middle but I changed now to .grid system. Other question: Can I set a row height? That a input field is 200x100px size? – Victor Vincent Mar 22 '18 at 08:41
  • 1
    You do not need to use a row for that. Just modify the dimensions in the object itself using .config(width = x, height = y). This would make a problem though, because the objects below the input field would be off center. I recommend creating a Frame for this, or just use the place() method if you plan to do it. – Rohan Mar 24 '18 at 00:07