Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import sqlite3
  2. from tkinter import *
  3.  
  4. root = Tk()
  5. root.title("моя база")
  6. root.geometry("500x500")
  7. lbl4 = Label(root, text="Введите ваше имя:")
  8. lbl4.pack()
  9. textbox1 = Entry(root, width=30)
  10. textbox1.pack()
  11. cvar1 = StringVar()
  12. cvar1.set(0)
  13. c1 = Checkbutton(root, text=1, variable=cvar1, onvalue="(1,)", offvalue=0)
  14. c1.pack()
  15. cvar2 = StringVar()
  16. cvar2.set(0)
  17. c2 = Checkbutton(root, text=2, variable=cvar2, onvalue="(2,)", offvalue=0)
  18. c2.pack()
  19. cvar5 = StringVar()
  20. cvar5.set(0)
  21. c1 = Radiobutton(root, text=3, value="(3,)", variable=cvar5)
  22. c1.pack()
  23. c2 = Radiobutton(root, text=4, value="(4,)", variable=cvar5)
  24. c2.pack()
  25. def baza():
  26. conn = sqlite3.connect('1.db')
  27. cursor = conn.cursor()
  28. cursor.execute('CREATE TABLE IF NOT EXISTS sozd1(otv1 text,otv2 text,otv3 text,otv4 text)')
  29. a=[]
  30. u1=[textbox1.get(),cvar1.get(),cvar2.get(),cvar5.get()]
  31. a.append(u1)
  32. for i in a:
  33. cursor.execute('INSERT INTO sozd1 VALUES(?,?,?,?)', i)
  34. conn.commit()
  35. def baza2():
  36. conn = sqlite3.connect('1.db')
  37. cursor = conn.cursor()
  38. cursor.execute('SELECT * FROM sozd1 ')
  39. results1 = cursor.fetchall()
  40. conn.commit()
  41. print(results1)
  42. def obn():
  43. textbox1.delete(0, END)
  44. cvar2.set(0)
  45. cvar1.set(0)
  46. cvar5.set(0)
  47. button1 = Button(root, text="добавить", command=baza)
  48. button1.pack()
  49. button2 = Button(root, text="вывести", command=baza2)
  50. button2.pack()
  51. button3 = Button(root, text="нвоая запись", command=obn)
  52. button3.pack()
  53. root.mainloop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement