|
|||
Приложение А. Листинг программы ⇐ ПредыдущаяСтр 4 из 4 Приложение А Листинг программы
from tkinter import Tk, BOTH, Listbox, StringVar, END, ttk, Button from tkinter.ttk import Frame, Label import sqlite3 import tkinter as tk
#------------------------------------------------------------------------------------------- sqlite_connection = sqlite3.connect('Ticket.sqlite3') cursor = sqlite_connection.cursor() print("Подключен к SQLite\n")
sqlite_select_query = """SELECT * from Matches""" cursor.execute(sqlite_select_query) records = cursor.fetchall() cursor.close() print(records)
MainList = list() for i in range(len(records)): textTitle = str(records[i][0]) + " " + str(records[i][1]) + " " + str(records[i][2]) MainList.append(textTitle) print(textTitle) print(MainList) #-------------------------------------------------------------------------------------------
# Таблица def OpenWorkedFrame(self, TableName): data = () print("Integer" + str(TableName)) self.FrameMain.destroy() with sqlite3.connect('Ticket.sqlite3') as connection: cursor = connection.cursor() cursor.execute("SELECT * FROM " + "Integer" + str(TableName)) data = (row for row in cursor.fetchall()) self.FrameMain = Frame(root, width = 800, height = 300) self.FrameMain.place(x = 165, y = 25)
table = Table(self.FrameMain, headings=('Место', 'Свободно\Занято', 'Цена'), rows=data) table.place(x = 0, y = 0)
# Окно размещения таблицы и скролл бар class Table(tk.Frame): def __init__(self, parent=None, headings=tuple(), rows=tuple()): super().__init__(parent)
table = ttk.Treeview(self, show="headings", selectmode="browse") table["columns"] = headings table["displaycolumns"] = headings
for head in headings: table.heading(head, text=head, anchor=tk.CENTER) table.column(head, anchor=tk.CENTER)
for row in rows: table.insert('', tk.END, values=tuple(row))
scrolltable = tk.Scrollbar(self, command=table.yview) table.configure(yscrollcommand=scrolltable.set) scrolltable.pack(side=tk.RIGHT, fill=tk.Y) table.pack(expand=tk.YES, fill=tk.BOTH)
# Список выбора class Example(Frame):
def __init__(self): super().__init__() self.initUI()
def initUI(self): global MainList
self.master.title("Список в Tkinter") self.pack(fill=BOTH, expand=1)
acts = MainList
lb = Listbox(self, width = 25, height = 35)
for i in acts: lb.insert(END, i)
lb.bind("<<ListboxSelect>>", self.onSelect)
lb.place(x = 5, y = 25)
self.var = StringVar() print(self.var) self.label = Label(self, text=0, textvariable=self.var) self.label.pack() self.Button_1 = Button(self, width = 12, height = 1, text = "Обновить") self.Button_1.place(x = 165, y = 560) self.Button_2 = Button(self, width = 12, height = 1, text = "Добавить") self.Button_2.place(x = 260, y = 560) self.Button_3 = Button(self, width = 12, height = 1, text = "Удалить") self.Button_3.place(x = 355, y = 560) self.Button_4 = Button(self, width = 12, height = 1, text = "Выход") self.Button_4.place(x = 450, y = 560)
def onSelect(self, val): try: sender = val.widget idx = sender.curselection() value = sender.get(idx) Integer = str(value[0:5]).split(" ") OpenWorkedFrame(Integer[0]) print("Вывод первого символа", Integer[0]) except: print("Список пуст") Integer = str(value[0:5]).split(" ") print("Вывод первого символа", Integer[0])
self.var.set(value) print (value)
root = Tk() ex = Example() root.geometry("1200x610+100+100") root["bg"] = "Silver" root.mainloop()
|
|||
|