Can someone show me how I can add a listbox to "paneWindow"?
Take this code as an example: can the left-hand window be made into a
listbox?
The problem can be fixed.
Don't use a wildcard. Use this import tkinter as tk
. Then use tk.
prefix.
I added some colors. So you can see panedWindow
adjustment.
- Add
StringVar()
- Add
Listbox
widget.
The red color is the Entry
widget
The green color is the Listbox
.
The aqua color is the Scale
widget.
The orange color is the Button
widget
You're ready to go.
Snippet re-modified.
import tkinter as tk
mainWindow = tk.Tk()
mainWindow.title("PanedWindow Example")
mainWindow.geometry('350x200')
variable_string = tk.StringVar()
variable_string.set('This is left Entry')
m1 = tk.PanedWindow(mainWindow, orient=tk.HORIZONTAL)
m1.pack(fill=tk.BOTH, expand=1)
label = tk.Entry(m1, textvariable=variable_string, bg="red", bd=5)
m1.add(label, stretch="always")
lstbox = tk.Listbox(m1, bg="green")
m1.add(lstbox, stretch="always")
m2 = tk.PanedWindow(m1, orient=tk.VERTICAL)
m1.add(m2, stretch="never")
topScale = tk.Scale(m2, orient=tk.HORIZONTAL, bg='aqua')
m2.add(topScale)
bottom = tk.Button(m2, text="OK", bg='orange')
m2.add(bottom)
mainWindow.mainloop()
Screenshot:
Entry
toListbox
?