Creating a simple login application using Kivy GUI and validating the credentials using a pandas DataFrame can be an engaging way to understand GUI development and data handling. Below is a basic example to get you started:
Let's assume you have a simple CSV file users.csv with usernames and passwords:
username,password user1,pass1 user2,pass2 user3,pass3
import pandas as pd
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.popup import Popup
class LoginApp(App):
def build(self):
self.df = pd.read_csv('users.csv')
self.box = BoxLayout(orientation='vertical')
self.username = TextInput(hint_text='Enter Username', multiline=False)
self.password = TextInput(hint_text='Enter Password', password=True, multiline=False)
btn = Button(text="Login")
btn.bind(on_press=self.validate_user)
self.box.add_widget(self.username)
self.box.add_widget(self.password)
self.box.add_widget(btn)
return self.box
def validate_user(self, instance):
user = self.username.text
pwd = self.password.text
# Check if user exists in the DataFrame
valid_user = self.df[(self.df['username'] == user) & (self.df['password'] == pwd)]
if not valid_user.empty:
popup = Popup(title='Login Successful',
content=Label(text='Welcome, {}!'.format(user)),
size_hint=(None, None), size=(200, 200))
else:
popup = Popup(title='Login Failed',
content=Label(text='Invalid Credentials'),
size_hint=(None, None), size=(200, 200))
popup.open()
if __name__ == "__main__":
LoginApp().run()
When you run the code, it will present a simple Kivy window where you can input a username and password. On pressing the "Login" button, it will check the credentials against the data in users.csv and display a popup message indicating if the login was successful or failed.
Make sure to have Kivy and pandas installed:
pip install kivy pandas
This example is basic and is meant for demonstration purposes. In real-world applications, passwords should never be stored in plain text and should be securely hashed.
mouse-cursor union windows-server-2012 native icu awt segue web asp.net-core-routing ethernet