Guest User

Untitled

a guest
Sep 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import ttk
  3. import sqlite3
  4.  
  5. class Main(tk.Frame):
  6. def __init__(self, root):
  7. super().__init__(root)
  8. self.init_main()
  9.  
  10. def init_main(self):
  11.  
  12. toolbar = tk.Frame(bg='#d7d8e0', bd=2)
  13. toolbar.pack(side=tk.LEFT,fil=tk.Y)
  14.  
  15. self.add_img = tk.PhotoImage(file='add.png')
  16. btn_open_dialog = tk.Button(toolbar, text='Добавить', command = self.open_dialog, bg='#d7d8e0', bd = 0,
  17. compound = tk.TOP, image = self.add_img)
  18. btn_open_dialog.pack(side=tk.TOP)
  19.  
  20. self.tree = ttk.Treeview(self, column=('ID','description','costs','total'), height=15 , show='headings')
  21.  
  22. self.tree.column('ID', width=30, anchor=tk.CENTER)
  23. self.tree.column('description', width=300, anchor=tk.CENTER)
  24. self.tree.column('costs', width=150, anchor=tk.CENTER)
  25. self.tree.column('total',width=100, anchor=tk.CENTER)
  26.  
  27. self.tree.heading('ID', text='№')
  28. self.tree.heading('description', text='Описание')
  29. self.tree.heading('costs', text='Сумма')
  30. self.tree.heading('total',text='Итог')
  31.  
  32. self.tree.pack()
  33.  
  34.  
  35. def open_dialog(self):
  36. Child()
  37.  
  38.  
  39.  
  40. class Child(tk.Toplevel):
  41. def __init__(self):
  42. super().__init__(root)
  43. self.init_child()
  44.  
  45. def init_child(self):
  46. BD().create()
  47.  
  48. self.title('Доходы/Расходы')
  49. self.geometry('400x220+400+300')
  50.  
  51. label_description = tk.Label(self, text='Описание: ')
  52. label_description.place(x=50, y=50)
  53. label_select = tk.Label(self, text='Доходы/Расходы: ')
  54. label_select.place(x=50, y=80)
  55. label_sum = tk.Label(self, text='Сумма: ')
  56. label_sum.place(x=50, y=110)
  57.  
  58.  
  59. self.entry_description = ttk.Entry(self)
  60. self.entry_description.place(x=200,y=50)
  61. self.entry_money = ttk.Entry(self)
  62. self.entry_money.place(x=200,y=110)
  63.  
  64. self.combobox = ttk.Combobox(self, values=(u'Доходы',u'Расходы'),state='readonly')
  65. self.combobox.current(0)
  66. self.combobox.place(x=200,y=80)
  67.  
  68. btn_add = tk.Button(self, text='Добавить', command = BD().add_item())
  69. btn_add.place(x=220, y=170)
  70. btn_add.bind('<Button-1>')
  71.  
  72. btn_cancel = tk.Button(self, text='Отменить', command=lambda: self.destroy())
  73. btn_cancel.place(x=300, y=170)
  74. btn_cancel.bind('<Button-1>')
  75.  
  76.  
  77. self.grab_set()
  78. self.focus_set()
  79.  
  80.  
  81.  
  82. class BD:
  83. def create(self):
  84. conn = sqlite3.connect('finance.db')
  85. cursor = conn.cursor()
  86.  
  87. cursor.execute("""CREATE TABLE IF NOT EXISTS albums (ID integer primary key,
  88. description text,
  89. costs text,
  90. total real)""")
  91.  
  92. conn.commit()
  93.  
  94. def add_item(self):
  95. cursor = sqlite3.connect('finance.db').cursor()
  96. cursor.execute('''INSERT INTO albums(ID, description, costs, total) VALUES('1','self.entry_description.get()', 'self.combobox.get()','self.entry_money.get()')''')
  97.  
  98. sqlite3.connect('finanace.db').commit()
  99.  
  100. def delete_item(self):
  101. pass
  102.  
  103.  
  104.  
  105.  
  106. if __name__=="__main__":
  107. root = tk.Tk()
  108. app = Main(root)
  109. app.pack()
  110. root.title('Доходы/Расходы')
  111. root.geometry('650x450+300+200')
  112. root.resizable(False, False)
  113. root.mainloop()
Add Comment
Please, Sign In to add comment