Using tkinter in python 3.4. I'm struggling to place a list box without it automatically moving all other elements. The example code is using the grid placement. I've also attempted to use .pack() and .place(). I've tried to embed it into several frames, I've tried rowspan and columnspan.
The listbox1 is currently commented, this shows how the window should look, once this line is uncommented the positioning of the elements change. Id like to have the list box in the position under the "clear answers" button without effecting the other elements.
import sys
import time
import tkinter
from tkinter import *
from tkinter import messagebox
from tkinter import filedialog
def CreateWindow():
#Create the window and the menu bar
MainWindow = Tk()
MainWindow.resizable(width=False, height=False)
MainWindow.geometry("450x260+150+150")
#Create the frame
TopFrame = Frame(MainWindow).grid(row=0,column=0)
#Top Labels
a = Label(TopFrame,text="aaaa aaaaa aaa aaaa \naa aaaaaaa aaaaa:").grid(row=0,column=0)
b = Label(TopFrame, text="aaaa aaaaa aaa aaaa \naa aaaaaaa aaaa?:").grid(row=0,column=1)
c = Label(TopFrame, text="aaaa aa aaaaaaaa aaaaaaa:").grid(row=0,column=2)
#Left Radio Buttons
d = Radiobutton(TopFrame, text="aaaaa").grid(row=1,column=0,sticky=W)
e = Radiobutton(TopFrame, text="aaaaa").grid(row=2,column=0,sticky=W)
f = Radiobutton(TopFrame, text="aaaaa").grid(row=3,column=0,sticky=W)
g = Radiobutton(TopFrame, text="aaaaa").grid(row=4,column=0,sticky=W)
#Right Radio Buttons
h = Radiobutton(TopFrame, text="aaaaa").grid(row=1,column=1,sticky=W)
i = Radiobutton(TopFrame, text="aaaaa").grid(row=2,column=1,sticky=W)
j = Radiobutton(TopFrame, text="aaaaa").grid(row=3,column=1,sticky=W)
k = Radiobutton(TopFrame, text="aaaaa").grid(row=4,column=1,sticky=W)
#Under left radio buttons
l = Label(TopFrame,text="aaaaaa aa aaaaaaaa aaaaaa aaaaaa").grid(row=5,column=0,columnspan=2)
m = Entry(TopFrame).grid(row=6,column=0,columnspan=2)
n = Button(TopFrame,text="aaaaaaa").grid(row=7,column=0,columnspan=2)
o = Label(TopFrame,text="aaaaa aaaaa aa").grid(row=8,column=0,columnspan=2)
#clear button and list box
ClearButton = Button(TopFrame,text="Clear answers").grid(row=1,column=2)
#-----List box should be under the convert button and should make other elements move-----
#ListBox1 = Listbox(TopFrame).grid(row=1,column=2)
MainWindow.mainloop()
CreateWindow()
Is there anyway to position an element that doesn't effect elements around it, set an element to be on a higher layer, make it invisible to other elements or just solve this problem? Any help is massively appreciated!
a,b,c,ListBox1, etc. each point toNone, which is the value returned bygrid(). To avoid this, assign a widget in one statement, and thengrid()it in a separate statement.gridand/orpack, and your GUI will be more resilient in the face of resizing or different sized fonts or resolutions.