Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import ttk
- import sqlite3
- class Main(tk.Frame):
- def __init__(self, root):
- super().__init__(root)
- self.init_main()
- def init_main(self):
- toolbar = tk.Frame(bg='#d7d8e0', bd=2)
- toolbar.pack(side=tk.LEFT,fil=tk.Y)
- self.add_img = tk.PhotoImage(file='add.png')
- btn_open_dialog = tk.Button(toolbar, text='Добавить', command = self.open_dialog, bg='#d7d8e0', bd = 0,
- compound = tk.TOP, image = self.add_img)
- btn_open_dialog.pack(side=tk.TOP)
- self.tree = ttk.Treeview(self, column=('ID','description','costs','total'), height=15 , show='headings')
- self.tree.column('ID', width=30, anchor=tk.CENTER)
- self.tree.column('description', width=300, anchor=tk.CENTER)
- self.tree.column('costs', width=150, anchor=tk.CENTER)
- self.tree.column('total',width=100, anchor=tk.CENTER)
- self.tree.heading('ID', text='№')
- self.tree.heading('description', text='Описание')
- self.tree.heading('costs', text='Сумма')
- self.tree.heading('total',text='Итог')
- self.tree.pack()
- def open_dialog(self):
- Child()
- class Child(tk.Toplevel):
- def __init__(self):
- super().__init__(root)
- self.init_child()
- def init_child(self):
- BD().create()
- self.title('Доходы/Расходы')
- self.geometry('400x220+400+300')
- label_description = tk.Label(self, text='Описание: ')
- label_description.place(x=50, y=50)
- label_select = tk.Label(self, text='Доходы/Расходы: ')
- label_select.place(x=50, y=80)
- label_sum = tk.Label(self, text='Сумма: ')
- label_sum.place(x=50, y=110)
- self.entry_description = ttk.Entry(self)
- self.entry_description.place(x=200,y=50)
- self.entry_money = ttk.Entry(self)
- self.entry_money.place(x=200,y=110)
- self.combobox = ttk.Combobox(self, values=(u'Доходы',u'Расходы'),state='readonly')
- self.combobox.current(0)
- self.combobox.place(x=200,y=80)
- btn_add = tk.Button(self, text='Добавить', command = BD().add_item())
- btn_add.place(x=220, y=170)
- btn_add.bind('<Button-1>')
- btn_cancel = tk.Button(self, text='Отменить', command=lambda: self.destroy())
- btn_cancel.place(x=300, y=170)
- btn_cancel.bind('<Button-1>')
- self.grab_set()
- self.focus_set()
- class BD:
- def create(self):
- conn = sqlite3.connect('finance.db')
- cursor = conn.cursor()
- cursor.execute("""CREATE TABLE IF NOT EXISTS albums (ID integer primary key,
- description text,
- costs text,
- total real)""")
- conn.commit()
- def add_item(self):
- cursor = sqlite3.connect('finance.db').cursor()
- cursor.execute('''INSERT INTO albums(ID, description, costs, total) VALUES('1','self.entry_description.get()', 'self.combobox.get()','self.entry_money.get()')''')
- sqlite3.connect('finanace.db').commit()
- def delete_item(self):
- pass
- if __name__=="__main__":
- root = tk.Tk()
- app = Main(root)
- app.pack()
- root.title('Доходы/Расходы')
- root.geometry('650x450+300+200')
- root.resizable(False, False)
- root.mainloop()
Add Comment
Please, Sign In to add comment