![](/img/trans.png)
[英]How can I call a variable defined inside a function from another file in Python?
[英]How can I call a variable from another python file which is re-defined
在 file1 中,“源”的值會根據我點擊的按鈕而改變。
source = 0
form_class2 = uic.loadUiType("./UI/Code.ui")[0]
class Code(QDialog, form_class2):
def __init__(self):
super().__init__()
self.setupUi(self)
self.pushButton.clicked.connect(self.aa)
self.pushButton_2.clicked.connect(self.bb)
def aa(self):
global source
source = 1
app.quit()
def bb(self):
global source
source = 2
app.quit()
if __name__ == "__main__":
app = QApplication(sys.argv)
myWindow = Code()
myWindow.show()
app.exec_()
import file2
然后在文件2中:
from file1 import source
print(source)
output 為 0
如何在 flie2 中獲得 output 的 1 或 2?
也許這可以幫助你
from file1 import *
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.