我需要在main.py里从window.py中获取列表text_content的值,但是失败了,有没有大佬知道为什么,代码如下
```python
mian.py
import window
from window import text_content
def main():
window.mainWin()
content = text_content
print(content)
main()
window.py
from tkinter import *
from tkinter import scrolledtext
text_content = []
class Application(Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.grid()
self.createWidget()
def createWidget(self):
self.la2 = Label(self, text='重量(kg):').grid(row=1, column=0, padx=(10, 0))
self.en2 = Entry(self)
self.en2.grid(row=1, column=1, columnspan=1, padx=(0, 10), ipadx=20) # 1行1列,跨2列
self.btn = Button(self, text="确定", command=self.click_btn).grid(row=1, column=2, padx=(0, 30), ipadx=30)
self.btn2 = Button(self, text="输入完毕", command=self.click_btn2).grid(row=4, column=2, padx=(0, 30), ipadx=30)
self.text = scrolledtext.ScrolledText(self, width=50, height=20)
self.text.grid(row=3, column=0, columnspan=3, padx=5, pady=10)
def click_btn(self):
input2 = self.en2.get()
str = input2 + ' '
#print(getinputstr)
print(input1, input2)
self.text.insert('1.0', str+'\n')
self.en2.delete(0, END)
def click_btn2(self):
text_content = (self.text.get('0.0', 'end').replace('\n', ' ')).split()
print(text_content)
#return text_content
def mainWin():
root = Tk()
root.title('NuContent')
sw = root.winfo_screenwidth()
sh = root.winfo_screenheight()
ww = 410
wh = 400
x = (sw - ww)/2
y = (sh - wh)/3
root.geometry("%dx%d+%d+%d" % (ww, wh, x, y))
root.resizable(False, False)
app = Application(master=root)
app.mainloop()
```