python文件运行哪一个_如何从另一个python文件运行文件

a.py

from kivy.app import App

from kivy.uix.dropdown import DropDown

from kivy.lang import Builder

class CustDrop(DropDown):

def __init__(self, **kwargs):

super(CustDrop, self).__init__( **kwargs)

self.select('')

kv_str = Builder.load_string('''

BoxLayout:

orientation: 'vertical'

BoxLayout:

canvas.before:

Rectangle:

pos: self.pos

size: self.size

Color:

rgb: (1,1,1)

size_hint_y:1

Button:

id: btn

text: 'test'

on_release: dropdown.open(self)

#size_hint_y: None

#height: '48dp'

CustDrop:

id: dropdown

Button:

text: 'Run another script'

size_hint_y: None

height: '48dp'

Label:

size_hint_x: 4

Label:

size_hint_y: 9

''')

class ExampleApp(App):

def build(self):

return kv_str

if __name__ =='__main__':

ExampleApp().run()

b.py

import kivy

kivy.require('1.0.6') # replace with your current kivy version !

from kivy.app import App

from kivy.uix.label import Label

class MyApp(App):

def build(self):

return Label(text='Hello world')

if __name__ == '__main__':

MyApp().run()

when i run a.py file after that i click on test then dropdown show 'run another script'.when i click on 'run another script'(sub menu of test) then how to run b.py(MyApp().run()).It should be print 'Hello world' in new window.

解决方案

The solution is as follow:

Snippet

a.py

...

kv_str = Builder.load_string('''

#:import os os

...

CustDrop:

id: dropdown

Button:

text: 'Run another script'

size_hint_y: None

height: '48dp'

on_release: os.system("python3 b.py")

Output

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值