python读取一个文件并写入另一个文件_从另一个文件获取变量-python

我正在创建一个Tkinter程序,该程序允许用户将文本输入一个漂亮的框而不是python shell.

因为我想在多个程序中使用它,所以我将其做成一个可以在其他文件中使用的函数.

我可以让它在另一个文件中运行,但不能导入变量,这是我的代码.

文件1:

import tkinter as tk

def input_text(label_text, button_text):

class SampleApp(tk.Tk):

def __init__(self):

tk.Tk.__init__(self)

self.entry = tk.Entry(self)

self.button = tk.Button(self, text=button_text, command=self.on_button)

self.label = tk.Label(self, text=label_text)

self.label.pack(side = 'top', pady = 5)

self.button.pack(side = 'bottom', pady = 5)

self.entry.pack()

def on_button(self):

answer = self.entry.get()

self.destroy()

w = SampleApp()

w.resizable(width=True, height=True)

w.geometry('{}x{}'.format(180, 90))

w.mainloop()

档案2:

import text_input as ti

from text_input import answer

ti.input_text('Enter some text', 'OK')

我收到错误ImportError:无法导入名称“答案”

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值