from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
BoxLayout:
padding: "10dp"
MDRaisedButton:
id: button_show_text
on_press: app.show_text()
MDTextField:
id: text_field
hint_text: "Helper text on error (press 'Enter')"
helper_text: "There will always be a mistake"
helper_text_mode: "on_error"
pos_hint: {"center_y": .5}
'''
class Test(MDApp):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.screen = Builder.load_string(KV)
def build(self):
self.screen.ids.text_field.bind(
on_text_validate=self.set_error_message,
on_focus=self.set_error_message,
)
return self.screen
def set_error_message(self, instance_text_field):
self.screen.ids.text_field.error = True
def show_text(self):
print(self.screen.ids.text_field.text)
Test().run()
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.config import Config
Config.set('graphics', 'width', '800')
Config.set('graphics', 'height', '400')
Config.set('graphics', 'resizable', '0')
class ThoughtApp(App):
def build (self):
base=(BoxLayout(orientation='vertical'))
fl=FloatLayout()
adduser=(Label(text='Добавить участника:',
pos=(-120,360),
font_size=22,
bold=True,
font_name='C:\Windows\Fonts\calibril.ttf',
size_hint=(.6,.1)))
fl.add_widget(adduser)
self.textinput=(TextInput(multiline=False,
pos=(225,355),
size_hint=(.5,.15),
font_size=16))
fl.add_widget(self.textinput)
plusbtn=(Button(size_hint=(27/800,30/800),
text='+',
pos=(635,366.5),
on_press=self.pluspress,
background_color=[.55,.55,.55,1],
background_normal=''))
fl.add_widget(plusbtn)
base.add_widget(fl)
self.names_gl=GridLayout(rows=1,)
base.add_widget(self.names_gl)
return base
def pluspress(self, event):
self.names_gl.add_widget(Button(text=self.textinput.text,
background_color=[.1,.9,.9,1],
background_normal=''))
self.textinput.text=''
if __name__ == '__main__':
ThoughtApp().run()
import sys
from PyQt5.QtWidgets import *
class Example(QWidget):
def __init__(self):
super().__init__()
self.resize(180, 40)
self.setWindowTitle("Пример")
self.button = QPushButton('изменить надпись нижней кнопки', self)
self.button.clicked.connect(self.function)
self.button_2 = QPushButton('Hello user!', self)
self.button_2.setGeometry(0, 20, 180, 25)
def function(self):
self.button_2.setText("Привет пользователь!")
def main():
app = QApplication(sys.argv)
window = Example()
window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()