簡體   English   中英

如何將存儲在函數中的變量值發送到另一個 Python 文件?

[英]How to send values of variables stored in a function to another Python file?

我正在嘗試創建一個程序來玩井字游戲。 現在我需要“console.py”在單擊鼠標按鈕時將鼠標的坐標發送到“core.py”。 這是代碼:-

控制台.py

import turtle
import core
import graphics


def findPos(eve):
    x, y = canvas.winfo_pointerxy()
    print(x, y)
    return x, y

canvas = turtle.getcanvas()
canvas.bind('<Button-1>', findPos)

核心文件

import numpy as np
import turtle
import console as tc

print(tc.x, tc.y)

現在,拋出一個錯誤:

AttributeError: module 'console' has no attribute 'x'

我該如何解決?

您需要在core.py本地調用該函數

import numpy as np
import turtle
import console as tc

x,y = tc.findPos(eve='eve')
print(x, y)

這是你想要的?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM