Dear all,
My window layout looks like this..
[img]http://i41.tinypic.com/hu27ax.jpg[/img]
First, the dialog box that consists of listbox would appear to ask for user input.
After the user input has been given, It will display in the next windows..
I have been trying to intergate the two coding together. However I can't get it to work..
The two codes are..
listbox
# a simple Tkinter ListBox example for multiline select
# use ctrl mouse click or shift mouse click
from Tkinter import *
import sqlite3
conn = sqlite3.connect('C:/test/test.db')
c = conn.cursor()
def get_list():
"""
function to read the listbox selection(s)
(mutliple lines can be selected)
and put the result(s) in a label
"""
# tuple of line index(es)
sel = listbox1.curselection()
print sel
c.close()
root = Tk()
# extended mode allows CTRL or SHIFT mouse selections
listbox1 = Listbox(root, selectmode = EXTENDED)
listbox1.pack()
# click the button to show the selection(s)
button1 = Button(root, text = "Get Selection(s)", command = get_list)
button1.pack()
# store some items in the listbox
c.execute('SELECT * FROM Location')
for item in c:
listbox1.insert(END, item[0])
# highlight line 3 of listbox (line 1 is zero)
# lb.selection_set(first, last=None) can select more than 1 line
listbox1.selection_set(3)
root.mainloop()
and dialog box..
from Tkinter import *
class MyDialog:
def __init__(self, parent):
top = self.top = Toplevel(parent)
Label(top, text="Value").pack()
self.e = Entry(top)
self.e.pack(padx=5)
b = Button(top, text="OK", command=self.ok)
b.pack(pady=5)
def ok(self):
print "value is", self.e.get()
self.top.destroy()
root = Tk()
d = MyDialog(root)
root.wait_window(d.top)
This is what I did and I am unsure where did I went wrong..
from Tkinter import *
conn = sqlite3.connect('C:/test/test.db')
c = conn.cursor()
class MyDialog:
def __init__(self, parent):
# extended mode allows CTRL or SHIFT mouse selections
listbox1 = Listbox(root, selectmode = EXTENDED)
listbox1.pack()
# click the button to show the selection(s)
button1 = Button(root, text = "Get Selection(s)", command = get_list)
button1.pack()
# store some items in the listbox
c.execute('SELECT * FROM Location')
for item in c:
listbox1.insert(END, item[0])
# highlight line 3 of listbox (line 1 is zero)
# lb.selection_set(first, last=None) can select more than 1 line
listbox1.selection_set(3)
def ok(self):
print "value is", self.e.get()
self.top.destroy()
def get_list():
"""
function to read the listbox selection(s)
(mutliple lines can be selected)
and put the result(s) in a label
"""
# tuple of line index(es)
sel = listbox1.curselection()
print sel
c.close()
root = Tk()
d = MyDialog(root)
root.wait_window(d.top)
Any comment on this will be great!! Thanks.. :|