<--SyntaxHighlighter--> SyntaxHighlighter.all();

1. 라이브러리 설치

pip install kivy

# 의존성 문제가 발생할 경우 (먼저 설치 필요)
pip install docutils pygments pypiwin32 kivy_deps.sdl2 kivy_deps.glew kivy_deps.gstreamer

 

2. main.py

from kivy.app import App
from kivy.uix.gridlayout import GridLayout  # 그리드 레이아웃
from kivy.uix.label import Label            # 라벨
from kivy.uix.textinput import TextInput    # 텍스트 인풋
from kivy.uix.button import Button
import os

class LoginScreen(GridLayout):
    def __init__(self, **kwargs):
        super(LoginScreen, self).__init__(**kwargs) # 오버로드되는 원래 클래스의 기능을 구현
        # fontName = '/'.join([os.getenv('SystemRoot'), '/fonts/NanumGothic.ttf'])
        fontName = 'NanumGothic.ttf'
        self.cols = 1

        self.upper = GridLayout()
        self.upper.cols = 2

        self.upper.add_widget(Label(text='이름',font_name=fontName))

        self.username = TextInput(multiline=False)
        self.upper.add_widget(self.username)

        self.upper.add_widget(Label(text='비밀번호',font_name=fontName))

        self.password = TextInput(password=True, multiline=False)
        self.upper.add_widget(self.password)

        self.add_widget(self.upper)

        self.lower = Button(text="Submit", font_size=40)
        self.lower.bind(on_press=self.pressed)  # on_press, on_release, on_state
        self.add_widget(self.lower)

    def pressed(self, instance):
        # print(instance, "is pressed")
        print("user name:", self.username.text, "password:", self.password.text)
        self.username.text = ""
        self.password.text = ""


class MyApp(App):
    def build(self):
        return LoginScreen()

if __name__ == '__main__':
    MyApp().run()

 

<결과>

+ Recent posts