Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python中获得GUI文本小部件的输出?_Python_Tkinter - Fatal编程技术网

如何在Python中获得GUI文本小部件的输出?

如何在Python中获得GUI文本小部件的输出?,python,tkinter,Python,Tkinter,我得到了两个文本小部件的代码,用于我必须编写的程序 player1_label = Label(window,text='Player 1:') player1_label.grid(row=0,column=0,sticky='W') player1_score = Label(window) player1_score.grid(row=0,column=1,sticky='W') player1_text = Text(window,width=30) player1_text.grid(

我得到了两个文本小部件的代码,用于我必须编写的程序

player1_label = Label(window,text='Player 1:')
player1_label.grid(row=0,column=0,sticky='W')
player1_score = Label(window)
player1_score.grid(row=0,column=1,sticky='W')
player1_text = Text(window,width=30)
player1_text.grid(row=1,column=0,columnspan=3,padx=10,pady=10)

player2_label = Label(window,text='Player 2:')
player2_label.grid(row=0,column=3,sticky='W')
player2_score = Label(window)
player2.grid(row=0,column=4,sticky='W')
player2_text = Text(window,width=30)
player2_text.grid(row=1,column=3,columnspan=3)

action_button = Button(window,text='Play',command=play_action)
action_button.grid(row=2,column=0,columnspan=2)
action_button['state'] = NORMAL
我已经为
do\u action()
编写了一个函数,它会打印一些东西。当我点击操作按钮时,我正在打印的字符串最终出现在解释器中,而不是文本小部件中。如何指定哪些字符串进入哪个小部件以及小部件的哪个窗口?

而不是

print('hello')

或类似的

继续阅读,了解如何操作各种小部件

player2_text.insert(END, 'hello')