Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.49 KB | None | 0 0
  1. Exception in Tkinter callback
  2. Traceback (most recent call last):
  3. File "C:UsersadamAppDataLocalProgramsPythonPython36-32libtkinter__init__.py", line 1702, in __call__
  4. return self.func(*args)
  5. File "C:A LEVELSComputingatomactual resultsworkingMain.py", line 54, in login
  6. self.test()
  7. File "C:A LEVELSComputingatomactual resultsworkingMain.py", line 37, in test
  8. Label(text=self.username.get(), font=('', 20), pady=5, padx=5).grid(sticky=W)
  9. File "C:UsersadamAppDataLocalProgramsPythonPython36-32libtkinter__init__.py", line 2223, in grid_configure
  10. + self._options(cnf, kw))
  11. _tkinter.TclError: cannot use geometry manager grid inside . which already has slaves managed by pack
  12. [Finished in 6.059s]
  13.  
  14. # imports
  15. from tkinter import *
  16. import tkinter as tk
  17. from tkinter import messagebox as ms
  18. import sqlite3
  19.  
  20.  
  21. # make database and users (if not exists already) table at programme start up
  22. with sqlite3.connect('quit.db') as db:
  23. c = db.cursor()
  24.  
  25. c.execute('CREATE TABLE IF NOT EXISTS user (var TEXT NOT NULL, username TEXT NOT NULL ,password TEXT NOT NULL);')
  26. db.commit()
  27.  
  28.  
  29. # main Class
  30.  
  31.  
  32. class main:
  33. def __init__(self, master):
  34. # Window
  35. self.master = master
  36. # Some Usefull variables
  37. self.var = tk.StringVar()
  38. self.username = StringVar()
  39. self.password = StringVar()
  40. self.n_username = StringVar()
  41. self.n_password = StringVar()
  42. # Create Widgets
  43. self.widgets()
  44.  
  45.  
  46.  
  47. def test(self):
  48. if self.var.get() == "HQ":
  49. root.geometry("1000x500")
  50. Label(text=self.username.get(), font=('', 20), pady=5, padx=5).grid(sticky=W)
  51.  
  52. # def pack():
  53. # if self.var.get() = "HQ"
  54.  
  55. # Login Function
  56. def login(self):
  57. # Establish Connection
  58. with sqlite3.connect('quit.db') as db:
  59. c = db.cursor()
  60.  
  61. # Find user If there is any take proper action
  62. find_user = ('SELECT * FROM user WHERE var = ? and username = ? and password = ?')
  63. c.execute(find_user, [(self.var.get()), (self.username.get()), (self.password.get())])
  64. result = c.fetchall()
  65. if result:
  66. self.logf.pack_forget()
  67. self.test()
  68. else:
  69. ms.showerror('Oops!', 'something is not right.')
  70.  
  71.  
  72. def new_user(self):
  73. # Establish Connection
  74. with sqlite3.connect('quit.db') as db:
  75. c = db.cursor()
  76.  
  77. # Find Existing username if any take proper action
  78. find_user = ('SELECT * FROM user WHERE username = ?')
  79. c.execute(find_user, [(self.username.get())])
  80. if c.fetchall():
  81. ms.showerror('Error!', 'Username Taken Try a Diffrent One.')
  82. else:
  83. ms.showinfo('Success!', 'Account Created!')
  84. self.log()
  85. # Create New Account
  86. insert = 'INSERT INTO user(var,username,password) VALUES(?,?,?)'
  87. c.execute(insert, [(self.var.get()), (self.n_username.get()), (self.n_password.get())])
  88. db.commit()
  89.  
  90. def dropbox(self, parent):
  91. OPTIONS = [
  92. "Please Select",
  93. "HQ",
  94. "Pilot",
  95. "Crew",
  96. "Customer"
  97. ]
  98. self.var.set(OPTIONS[0])
  99. return OptionMenu(parent, self.var, *OPTIONS)
  100.  
  101.  
  102. # Frame Packing Methords
  103. def log(self):
  104.  
  105. self.username.set('')
  106. self.password.set('')
  107. self.crf.pack_forget()
  108. self.head['text'] = 'LOGIN'
  109. self.logf.pack()
  110.  
  111. def cr(self):
  112. self.n_username.set('')
  113. self.n_password.set('')
  114. self.logf.pack_forget()
  115. self.head['text'] = 'Create Account'
  116. self.crf.pack()
  117.  
  118. # Draw Widgets
  119. def widgets(self):
  120. self.head = Label(self.master, text='LOGIN', font=('', 35), pady=10)
  121. self.head.pack()
  122. self.logf = Frame(self.master, padx=10, pady=10)
  123. Label(self.logf, text='Select:', font=('', 20), pady=5, padx=5).grid(row=1, column=0)
  124. self.dropbox(self.logf).grid(row=1, column=1, sticky=W)
  125. Label(self.logf, text='Username: ', font=('', 20), pady=5, padx=5).grid(row=2, column=0)
  126. Entry(self.logf, textvariable=self.username, bd=5, font=('', 15)).grid(row=2, column=1)
  127. Label(self.logf, text='Password: ', font=('', 20), pady=5, padx=5).grid(sticky=W)
  128. Entry(self.logf, textvariable=self.password, bd=5, font=('', 15), show='*').grid(row=3, column=1)
  129. Button(self.logf, text='Login', bd=3, font=('', 15), padx=5, pady=5, command=self.login).grid()
  130. Button(self.logf, text='Create Account', bd=3, font=('', 15), padx=5, pady=5, command=self.cr).grid(row=4, column=1)
  131. self.logf.pack()
  132.  
  133. self.crf = Frame(self.master, padx=10, pady=10)
  134. Label(self.crf, text='Select:', font=('', 20), pady=5, padx=5).grid(row=1, column=0)
  135. self.dropbox(self.crf).grid(row=1, column=1, sticky=W)
  136. Label(self.crf, text='Username: ', font=('', 20), pady=5, padx=5).grid(sticky=W)
  137. Entry(self.crf, textvariable=self.n_username, bd=5, font=('', 15)).grid(row=2, column=1)
  138. Label(self.crf, text='Password: ', font=('', 20), pady=5, padx=5).grid(sticky=W)
  139. Entry(self.crf, textvariable=self.n_password, bd=5, font=('', 15), show='*').grid(row=3, column=1)
  140. Button(self.crf, text='Create Account', bd=3, font=('', 15), padx=5, pady=5, command=self.new_user).grid()
  141. Button(self.crf, text='Go to Login', bd=3, font=('', 15), padx=5, pady=5, command=self.log).grid(row=4, column=1)
  142.  
  143.  
  144. # create window and application object
  145. root = tk.Tk()
  146. # root.title("Login Form")
  147. main(root)
  148. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement