tkinter에 데이터베이스 테이블을 표시하려고하는데 테이블 뷰의 마지막 행만 가져옵니다. tkinter에서 전체 행을 어떻게 얻을 수 있습니까?파이썬 3 : 데이터베이스의 마지막 행은 tkinter 테이블에서만 볼 수 있습니다.
사양 :
Python3, PostgreSQL을, psycopg2, tkinnter이 내가 tkinter output & Table rows
한 번 더 설명을 얻고있다 결과입니다
class MultiColumnListbox(object):
"""use a ttk.TreeView as a multicolumn ListBox"""
def __init__(self):
self.tree = None
self._setup_widgets()
self._build_tree()
def _setup_widgets(self):
s = """WOW CALL LIST"""
msg = ttk.Label(wraplength="4i", justify="left", anchor="n",
padding=(10, 2, 10, 6), text=s)
msg.pack(fill='x')
container = ttk.Frame()
container.pack(fill='both', expand=True)
# create a treeview with dual scrollbars
self.tree = ttk.Treeview(columns=car_header, show="headings")
vsb = ttk.Scrollbar(orient="vertical",
command=self.tree.yview)
hsb = ttk.Scrollbar(orient="horizontal",
command=self.tree.xview)
self.tree.configure(yscrollcommand=vsb.set,
xscrollcommand=hsb.set)
self.tree.grid(column=0, row=0, sticky='nsew', in_=container)
vsb.grid(column=1, row=0, sticky='ns', in_=container)
hsb.grid(column=0, row=1, sticky='ew', in_=container)
container.grid_columnconfigure(0, weight=1)
container.grid_rowconfigure(0, weight=1)
def _build_tree(self):
for col in car_header:
self.tree.heading(col, text=col.title(),
command=lambda c=col: sortby(self.tree, c, 0))
# adsjust the column's width to the header string
self.tree.column(col,
width=tkFont.Font().measure(col.title()))
for item in car_list:
self.tree.insert('', 'end', values=item)
# adjust column's width if necessary to fit each value
for ix, val in enumerate(item):
col_w = tkFont.Font().measure(val)
if self.tree.column(car_header[ix],width=None)<col_w:
self.tree.column(car_header[ix], width=col_w)
def sortby(tree, col, descending):
"""sort tree contents when a column header is clicked on"""
# grab values to sort
data = [(tree.set(child, col), child) \
for child in tree.get_children('')]
# if the data to be sorted is numeric change to float
#data = change_numeric(data)
# now sort the data in place
data.sort(reverse=descending)
for ix, item in enumerate(data):
tree.move(item[1], '', ix)
# switch the heading so it will sort in the opposite direction
tree.heading(col, command=lambda col=col: sortby(tree, col, \
int(not descending)))
# the test data ...
con = psycopg2.connect("dbname='wowcall' user='postgres' password='[email protected]'")
cur = con.cursor()
cur.execute("SELECT * FROM wowdata")
ver=cur.fetchall()
for row in ver:
print(row)
car_header = ['WOW ID',' Agent Name','Customer No']
car_list = [row]
if __name__ == '__main__':
root = tk.Tk()
root.title("WOW Call")
listbox = MultiColumnListbox()
root.mainloop()
사전에
감사합니다 필요 ... 특정 시간 간격으로 표를 자동으로 새로 고침 하시겠습니까?
어떻게 특정 시간 간격에서 테이블을 새로 고쳐야? – Deepak