这是我的Python文件内容,我制作了一个mysql数据库并将其连接到程序,我的主屏幕有问题,因为我正在尝试制作一个搜索栏
from kivy.app import App
import mysql.connector
from arabic_reshaper import reshape
from bidi.algorithm import get_display
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.widget import Widget
from kivy.graphics import Rectangle, Color
from kivy.core.window import Window
from kivy.uix.button import Button
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import StringProperty
sm=ScreenManager()
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="A.C.A_2024",
database="users_data"
)
my_cursor = mydb.cursor()
my_cursor.execute("SELECT * FROM data")
data=my_cursor.fetchall()
def arab(text):
return get_display(reshape(text))
class LoginPageLayout(Screen):
error_text=StringProperty("")
def SignIn(self,username,password):
print("hello")
for i in data:
if i[0] == username and i[1] == password:
print("hi")
print(username)
print(password)
sm.current="HomePage"
print("try again")
class SignUpLayout(Screen):
error_text = StringProperty("")
def SignUp(self,username,password):
if len(username)<8:
self.error_text="user name must be 8 charcters atleast"
elif len(password)<8:
self.error_text="password must be 8 characters atleast"
else:
print("hello")
my_cursor.execute("INSERT INTO data (username , password) VALUES (%s , %s)", (username, password))
mydb.commit()
print("done excecuting")
sm.current = "HomePage"
class HomePage(Screen):
pass
class ACAapp(App):
def build(self):
sm.add_widget(LoginPageLayout(name="LoginPageLayout"))
sm.add_widget(SignUpLayout(name="SignUpLayout"))
sm.add_widget(HomePage(name="HomePage"))
return sm
ACAapp().run()
这是我的 kivy 文件
<LoginPageLayout>:
BoxLayout:
padding: [50,10,50,30]
spacing: 20
orientation: "vertical"
Label:
text: "login page"
font_name: "andlso.ttf"
TextInput:
id: user
multiline: False
TextInput:
id: password
multiline: False
password: True
Button:
font_name: "andlso.ttf"
text: "login"
on_press: root.SignIn(user.text , password.text)
Button:
font_name: "andlso.ttf"
text: "don`t have an account? sign up"
on_press: root.manager.current="SignUpLayout"
<SignUpLayout>
BoxLayout:
font_size: 40
padding: [50,10,50,30]
spacing: 20
orientation: "vertical"
Label:
text: "sign up page"
font_name: "andlso.ttf"
TextInput:
id: user2
multiline: False
TextInput:
id: pass2
multiline: False
password: True
Label:
text: root.error_text
font_name: "andlso.ttf"
Button:
text: "sign up"
on_press: root.SignUp(user2.text,pass2.text)
<HomePage>:
canvas.before:
RoundedRectangle:
pos: 50 , self.height-75
size: self.width-50 , 50
radius: [(40,40),(40,40),(40,40),(40,40)]
TextInput:
size_hint: (None , None)
width: root.width-100
height: 50
pos: 75 , root.height-75
注册和登录屏幕已经完成,我正在主页上工作
我尝试在主屏幕中创建一个搜索栏,但活动时输入的文本颜色与矩形的颜色不同
要在 kivy 中指定 TextInput 的文本颜色,您可以编辑或添加属性并使用画布进行自定义:
TextInput:
height: dp(40)
pos_hint: {"center_x": .4, "top": .975}
font_size: "14sp"
hint_text_color: [0,0,0, .7]
foreground_color: [0,.1,1,1]
background_color: [1,1,1,0]
background_image: "a11.png" #this was a 100% transparent png image I use
background_normal: "a11.png"
background_active: "a11.png"
multiline: False
size_hint: .5 ,None
hint_text: 'Search here'
on_text: 'results or do somethin'
canvas.after:
Color:
rgba: [.42,.05,.6,.6]
Line:
width: dp(2)
rounded_rectangle:
(self.x, self.y, self.width-dp(20), dp(43),\
dp(8),dp(8),dp(8),dp(8),\
dp(50))