python功能主菜单_在python中为移动应用创建主菜单

I'm have trouble figuring out how to begin a code that displays a main menu. I want this main menu to display 5 different options that when on of them is clicked, it open that page/option. I also have Kivy installed, and the overall goal is to make a mobile app. My python experience is low, so I haven't actually written out any code for this goal but I have a full layout of what I want the app to look like.

Updated:

This is what I have so far.

mainMenu = {}

mainMenu ['1'] = 'Option 1'

mainMenu ['2'] = 'Option 2'

mainMenu ['3'] = 'Option 3'

mainMenu ['4'] = 'Option 4'

mainMenu ['5'] = 'Option 5'

print(mainMenu)

while True:

selection = input()

if selection == '1':

print('Page 1')

elif selection == '2':

print('Page 2')

elif selection == '3':

print('Page 3')

elif selection == '4':

print('Page 4')

elif selection == '5':

print('Page 5')

break

解决方案

Please refer to the example below and modify it as per your requirementst. I recommend reading the documentation abound Kivy Dropdown list.

Example

main.py

from kivy.app import App

from kivy.uix.dropdown import DropDown

from kivy.uix.floatlayout import FloatLayout

from kivy.config import Config

class SubMenu(DropDown):

pass

class MainMenu(FloatLayout):

def display_selected_submenu(self, instance, x):

print("Page " + x)

class TestApp(App):

title = "Kivy Drop-Down List Demo"

Config.set("graphics", "width", "800")

Config.set("graphics", "height", "480")

def build(self):

return MainMenu()

if __name__ == '__main__':

TestApp().run()

test.kv

#:kivy 1.10.0

#:import Factory kivy.factory.Factory

:

size_hint_y: None

height: 40

font_size: 18

:

on_select: app.root.display_selected_submenu(self, args[1])

CustomButton:

id: button1

text: 'Open'

txt: "1"

on_release: root.select(self.txt)

CustomButton:

id: button2

text: 'Save'

txt: "2"

on_release: root.select(self.txt)

CustomButton:

id: button3

text: 'Exit'

txt: "3"

on_release: root.select(self.txt)

:

canvas.before:

Color:

rgba: 0.5, 0.5, 0.5, 0.5

Rectangle:

pos: 0,0

size: self.width, self.height

Button:

id: mainbutton

text: "File Menu"

font_size: 20

size_hint: None, None

size: 150, 50

top: root.top

on_release: Factory.SubMenu().open(self)

Output

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值