Flet의 간단한 앱
다음은 내가 시도한 간단한 Flet 애플리케이션 개발의 예입니다. 앱의 페이지를 변경해 보세요. 문서에 명확한 지침이 없기 때문입니다. 대신 컨테이너를 하나씩 pop() 제거할 수 있습니다. 이것이 최선의 방법이 아닐 수도 있습니다. 하지만 앞으로는 더 나은 방법이 있기를 바랍니다.
앱 인덱스 페이지
def main(page: Page):
page.title = 'App wk18k'
page.theme = theme.Theme(color_scheme_seed="indigo")
page.theme_mode = "dark"
page.horizontal_alignment = 'center'
AppMain(page)
SwithMode(page)
page.update()
flet.app(target=main,port=25648,)
brownser://localhost:25648/
다크 모드와 라이트 모드를 전환합니다.
class SwithMode:
def __init__(self,page):
self.page = page
self.page.floating_action_button = FloatingActionButton("+",icon="add",content=Icon(icons.DARK_MODE))
self.page.floating_action_button.on_click = self.switch_mode
def switch_mode(self,e):
self.page.theme_mode="light" if self.page.theme_mode=="dark" else "dark"
self.page.floating_action_button.content = Icon(icons.LIGHT_MODE) if self.page.theme_mode=="dark" == "dark" else Icon(icons.DARK_MODE)
self.page.update()
기본 앱 페이지
class AppMain:
def __init__(self,page):
self.page = page
self.page.horizontal_alignment = 'center'
self.page.vertical_alignment = 'center'
self.TextHeaderWelcome = Text('Hello all members, this is wk-18k's test app.',style="headlineLarge",text_align='center')
self.BtnToRes = FilledButton('Press To Register',height=50,width=200)
self.BtnToRes.on_click = self.to_res
self.Container1 = Container(content=self.TextHeaderWelcome,margin=5,padding=padding.only(left=30,right=30))
self.Container2 = Container(content=self.BtnToRes,margin=5,padding=padding.only(left=30,right=30))
self.img = Image(src=f"/icons/icon-512.png",width=100,height=100,fit="contain",)
self.WidgetList = [self.img,self.Container1,self.Container2]
for i in self.WidgetList:
self.page.add(i)
self.page.update()
def to_res(self,event):
for i in self.WidgetList:
self.page.controls.pop()
AppRegister(self.page)
self.page.update()
앱 등록 페이지
class AppRegister:
def __init__(self,page):
self.page = page
self.page.horizontal_alignment = 'center'
self.page.vertical_alignment = 'start'
self.NameInput = TextField(label='First',hint_text='First Name',width=300)
self.SurnameInput = TextField(label='Last',hint_text='Last Name',width=300)
self.AgeInput = TextField(label='Age',hint_text='อายุ',width=300,keyboard_type='number',value = 0)
self.TextHeader = Text('Subscribe',style="displaySmall")
self.Submit = FilledButton('Register',height=50,width=200)
self.Submit.on_click = self.submit
self.BackMain = FilledButton('Back',height=50,width=200)
self.BackMain.on_click = self.back_main
self.Container1 = Container(content=self.TextHeader,margin=10,)
self.Container2 = Container(content=self.NameInput,margin=5,padding=padding.only(left=30,right=30))
self.Container3 = Container(content=self.SurnameInput,margin=5,padding=padding.only(left=30,right=30))
self.Container4 = Container(content=self.AgeInput,margin=5,padding=padding.only(left=30,right=30))
self.Container5 = Container(content=self.Submit,margin=5,padding=padding.only(left=30,right=30))
self.Container6 = Container(content=self.BackMain,margin=5,padding=padding.only(left=30,right=30))
self.InputList = [self.Container1,self.Container2,self.Container3,self.Container4,self.Container5,self.Container6]
for i in self.InputList:
self.page.add(i)
self.page.update()
def back_main(self,event):
for i in self.InputList:
self.page.controls.pop()
AppMain(self.page)
def submit(self,event):
import json
data = {
"id":self.page.session_id,
"first":self.NameInput.value,
"last":self.SurnameInput.value,
"age":self.AgeInput.value
}
with open('data.json','r') as f:
data_json = json.load(f)
data_json.append(data)
with open('data.json','w') as f:
json.dump(data_json,f)
# print(self.page.session_id)
# print(self.NameInput.value)
# print(self.SurnameInput.value)
# print(self.AgeInput.value)
시도 해봐
def main(page: Page):
page.title = 'App wk18k'
page.theme = theme.Theme(color_scheme_seed="indigo")
page.theme_mode = "dark"
page.horizontal_alignment = 'center'
AppMain(page)
SwithMode(page)
page.update()
flet.app(target=main,port=25648,)
brownser://localhost:25648/
class SwithMode:
def __init__(self,page):
self.page = page
self.page.floating_action_button = FloatingActionButton("+",icon="add",content=Icon(icons.DARK_MODE))
self.page.floating_action_button.on_click = self.switch_mode
def switch_mode(self,e):
self.page.theme_mode="light" if self.page.theme_mode=="dark" else "dark"
self.page.floating_action_button.content = Icon(icons.LIGHT_MODE) if self.page.theme_mode=="dark" == "dark" else Icon(icons.DARK_MODE)
self.page.update()
기본 앱 페이지
class AppMain:
def __init__(self,page):
self.page = page
self.page.horizontal_alignment = 'center'
self.page.vertical_alignment = 'center'
self.TextHeaderWelcome = Text('Hello all members, this is wk-18k's test app.',style="headlineLarge",text_align='center')
self.BtnToRes = FilledButton('Press To Register',height=50,width=200)
self.BtnToRes.on_click = self.to_res
self.Container1 = Container(content=self.TextHeaderWelcome,margin=5,padding=padding.only(left=30,right=30))
self.Container2 = Container(content=self.BtnToRes,margin=5,padding=padding.only(left=30,right=30))
self.img = Image(src=f"/icons/icon-512.png",width=100,height=100,fit="contain",)
self.WidgetList = [self.img,self.Container1,self.Container2]
for i in self.WidgetList:
self.page.add(i)
self.page.update()
def to_res(self,event):
for i in self.WidgetList:
self.page.controls.pop()
AppRegister(self.page)
self.page.update()
앱 등록 페이지
class AppRegister:
def __init__(self,page):
self.page = page
self.page.horizontal_alignment = 'center'
self.page.vertical_alignment = 'start'
self.NameInput = TextField(label='First',hint_text='First Name',width=300)
self.SurnameInput = TextField(label='Last',hint_text='Last Name',width=300)
self.AgeInput = TextField(label='Age',hint_text='อายุ',width=300,keyboard_type='number',value = 0)
self.TextHeader = Text('Subscribe',style="displaySmall")
self.Submit = FilledButton('Register',height=50,width=200)
self.Submit.on_click = self.submit
self.BackMain = FilledButton('Back',height=50,width=200)
self.BackMain.on_click = self.back_main
self.Container1 = Container(content=self.TextHeader,margin=10,)
self.Container2 = Container(content=self.NameInput,margin=5,padding=padding.only(left=30,right=30))
self.Container3 = Container(content=self.SurnameInput,margin=5,padding=padding.only(left=30,right=30))
self.Container4 = Container(content=self.AgeInput,margin=5,padding=padding.only(left=30,right=30))
self.Container5 = Container(content=self.Submit,margin=5,padding=padding.only(left=30,right=30))
self.Container6 = Container(content=self.BackMain,margin=5,padding=padding.only(left=30,right=30))
self.InputList = [self.Container1,self.Container2,self.Container3,self.Container4,self.Container5,self.Container6]
for i in self.InputList:
self.page.add(i)
self.page.update()
def back_main(self,event):
for i in self.InputList:
self.page.controls.pop()
AppMain(self.page)
def submit(self,event):
import json
data = {
"id":self.page.session_id,
"first":self.NameInput.value,
"last":self.SurnameInput.value,
"age":self.AgeInput.value
}
with open('data.json','r') as f:
data_json = json.load(f)
data_json.append(data)
with open('data.json','w') as f:
json.dump(data_json,f)
# print(self.page.session_id)
# print(self.NameInput.value)
# print(self.SurnameInput.value)
# print(self.AgeInput.value)
시도 해봐
class AppMain:
def __init__(self,page):
self.page = page
self.page.horizontal_alignment = 'center'
self.page.vertical_alignment = 'center'
self.TextHeaderWelcome = Text('Hello all members, this is wk-18k's test app.',style="headlineLarge",text_align='center')
self.BtnToRes = FilledButton('Press To Register',height=50,width=200)
self.BtnToRes.on_click = self.to_res
self.Container1 = Container(content=self.TextHeaderWelcome,margin=5,padding=padding.only(left=30,right=30))
self.Container2 = Container(content=self.BtnToRes,margin=5,padding=padding.only(left=30,right=30))
self.img = Image(src=f"/icons/icon-512.png",width=100,height=100,fit="contain",)
self.WidgetList = [self.img,self.Container1,self.Container2]
for i in self.WidgetList:
self.page.add(i)
self.page.update()
def to_res(self,event):
for i in self.WidgetList:
self.page.controls.pop()
AppRegister(self.page)
self.page.update()
class AppRegister:
def __init__(self,page):
self.page = page
self.page.horizontal_alignment = 'center'
self.page.vertical_alignment = 'start'
self.NameInput = TextField(label='First',hint_text='First Name',width=300)
self.SurnameInput = TextField(label='Last',hint_text='Last Name',width=300)
self.AgeInput = TextField(label='Age',hint_text='อายุ',width=300,keyboard_type='number',value = 0)
self.TextHeader = Text('Subscribe',style="displaySmall")
self.Submit = FilledButton('Register',height=50,width=200)
self.Submit.on_click = self.submit
self.BackMain = FilledButton('Back',height=50,width=200)
self.BackMain.on_click = self.back_main
self.Container1 = Container(content=self.TextHeader,margin=10,)
self.Container2 = Container(content=self.NameInput,margin=5,padding=padding.only(left=30,right=30))
self.Container3 = Container(content=self.SurnameInput,margin=5,padding=padding.only(left=30,right=30))
self.Container4 = Container(content=self.AgeInput,margin=5,padding=padding.only(left=30,right=30))
self.Container5 = Container(content=self.Submit,margin=5,padding=padding.only(left=30,right=30))
self.Container6 = Container(content=self.BackMain,margin=5,padding=padding.only(left=30,right=30))
self.InputList = [self.Container1,self.Container2,self.Container3,self.Container4,self.Container5,self.Container6]
for i in self.InputList:
self.page.add(i)
self.page.update()
def back_main(self,event):
for i in self.InputList:
self.page.controls.pop()
AppMain(self.page)
def submit(self,event):
import json
data = {
"id":self.page.session_id,
"first":self.NameInput.value,
"last":self.SurnameInput.value,
"age":self.AgeInput.value
}
with open('data.json','r') as f:
data_json = json.load(f)
data_json.append(data)
with open('data.json','w') as f:
json.dump(data_json,f)
# print(self.page.session_id)
# print(self.NameInput.value)
# print(self.SurnameInput.value)
# print(self.AgeInput.value)
시도 해봐
레포
읽어 주셔서 감사합니다
Reference
이 문제에 관하여(Flet의 간단한 앱), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://dev.to/watchakorn18k/simple-app-from-flet-8m6
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(Flet의 간단한 앱), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/watchakorn18k/simple-app-from-flet-8m6텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)