I'm currently making a database using MySql in Python in order to collect information about hospitals. I've created different programs (like one for the registration form, one for the database, and so on.)
and imported them (To execute them) in various parts of my other programs. However, one of them does not perform its function and raises an error.
Here is the overall procedure:
. Make a program to create a database using MySql
. Make a program to create 2 buttons using Pygame (Register and login)
. Make the program to create a registration form when Register is clicked.
. Send the details of it to the database
Overall, the program works if the Pygame buttons program isn't included. The Database program executes the Registration form program, which obtains the details entered, and is sent by the Database programme to the database created. However, executing the Registration Form when I click on the Register button (in the Buttons program) raises an error(uncaught exception of type NSException') and python closes. I've tried many ways of doing the same, even of copy-pasting the code into the program itself, but they both yield the same result.
Could anyone help to correct this error
Here is the code I've used for the Button:
and imported them (To execute them) in various parts of my other programs. However, one of them does not perform its function and raises an error.
Here is the overall procedure:
. Make a program to create a database using MySql
. Make a program to create 2 buttons using Pygame (Register and login)
. Make the program to create a registration form when Register is clicked.
. Send the details of it to the database
Overall, the program works if the Pygame buttons program isn't included. The Database program executes the Registration form program, which obtains the details entered, and is sent by the Database programme to the database created. However, executing the Registration Form when I click on the Register button (in the Buttons program) raises an error(uncaught exception of type NSException') and python closes. I've tried many ways of doing the same, even of copy-pasting the code into the program itself, but they both yield the same result.
Could anyone help to correct this error
Here is the code I've used for the Button:
import pygame pygame.init() class button(): def __init__(self, colour, x, y, width, height, text=''): self.colour = colour self.x = x self.y = y self.width = width self.height = height self.text = text def draw(self, win, outline=None): if outline: pygame.draw.rect(win, outline, (self.x - 2, self.y - 2, self.width + 4, self.height + 4), 0) pygame.draw.rect(win, self.colour, (self.x, self.y, self.width, self.height), 0) if self.text != '': font = pygame.font.SysFont('comicsans', 35) text = font.render(self.text, 1, (0, 0, 0)) win.blit(text, ( self.x + (self.width / 2 - text.get_width() / 2), self.y + (self.height / 2 - text.get_height() / 2))) def isOver(self, pos): if pos[0] > self.x and pos[0] < self.x + self.width: if pos[1] > self.y and pos[1] < self.y + self.height: return True return False def redrawGameWindow(): win.fill((255, 255, 255)) loginButton.draw(win) registerButton.draw(win) def register(): import Databases run = True loginButton = button((0, 255, 0), 175, 150, 150, 60, 'Login') registerButton = button((255, 0, 0), 175, 300, 150, 60, 'Register') while run: redrawGameWindow() pygame.display.update() for event in pygame.event.get(): pos = pygame.mouse.get_pos() if event.type == pygame.QUIT: run = False pygame.quit() quit() if event.type == pygame.MOUSEBUTTONDOWN: if loginButton.isOver(pos): print("Login") if registerButton.isOver(pos): register() if event.type == pygame.MOUSEMOTION: if loginButton.isOver(pos): loginButton.colour = (0, 175, 0) else: loginButton.colour = (0, 255, 0) if registerButton.isOver(pos): registerButton.colour = (255, 0, 0) else: registerButton.colour = (175, 0, 0) Here is the code I've used for the Registration Form: from tkinter import * tk = Tk() tk.geometry('500x500') tk.title("Registration Form") Heading = Label(tk, text = "Registration Form", width = 20, font = ('bold', 20)) Heading.place(x = 120, y = 53) hospitalName = Label(tk, text = "Hospital Name", width = 20, font = ('comicsans', 15)) hospitalName.place(x = 80, y = 130 ) entryBox_hosp = Entry(tk) entryBox_hosp.place(x = 229, y = 130) password = Label(tk, text = "Password", width = 20, font = ('comicsans', 15)) password.place(x = 75, y = 180) entryBox_pass = Entry(tk) entryBox_pass.place(x = 229, y = 180) coordinates = Label(tk, text = "Coordinates", width = 20, font = ('comicsans', 15)) coordinates.place(x = 80, y = 230) entryBox_crds = Entry(tk) entryBox_crds.place(x = 229, y = 230) def transfer(): global hosp_name global password global coordinates hosp_name = entryBox_hosp.get() password = entryBox_pass.get() coordinates = entryBox_crds.get() submit = Button(tk, text = "Submit", fg = 'red', width = 20, command = transfer) submit.place(x = 150, y = 350) mainloop()For the Database:
import mysql.connector import Registration_Form mydb = mysql.connector.connect( host = #, user = #, passwd = #, database = # ) myCursor = mydb.cursor() sqlFormula = "INSERT INTO UserInfo (hosp_name, password, coordinates) VALUES (%s, %s, %s)" hospital = [Registration_Form.hosp_name, Registration_Form.password, Registration_Form.coordinates] myCursor.execute(sqlFormula, hospital) mydb.commit()NOTE: The database has already been created. These are just the steps of populating my database (The one which is being executed)