Skip to content

Instantly share code, notes, and snippets.

@landv
Created March 22, 2024 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save landv/3e5961f6c3f44e66c4afe3ebd2aa26bd to your computer and use it in GitHub Desktop.
Save landv/3e5961f6c3f44e66c4afe3ebd2aa26bd to your computer and use it in GitHub Desktop.
python WOL唤醒使用flet开发的页面
import flet as ft
from flet_core import padding
from wakeonlan import send_magic_packet
from time import sleep
from pythonping import ping
def main(page: ft.Page):
page.title = "WOL启动"
target_host = "你的IP"
def wol_start(e):
mac_address = '你的mac地址'
send_magic_packet(mac_address)
isTrue = False
for i in range(30):
response_list = ping(target_host, count=1)
for response in response_list:
print(response)
page.add(ft.Text(f"{response},{i}!"))
if response.success:
isTrue = True
break
if isTrue:
page.clean()
initstart()
page.add(ft.Text(f"启动成功~~~"))
break
sleep(0.5)
sleep(1)
page.clean()
initstart()
print("ok")
def initstart():
page.add(
ft.ResponsiveRow([
ft.Container(
ft.ElevatedButton(text="WOL-Start-myPC", on_click=wol_start),
padding=padding.only(top=55)
),
])
)
initstart()
# ft.app(target=main)
ft.app(target=main, host='0.0.0.0', port=8080, view=ft.AppView.WEB_BROWSER)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment