python tkinter如何从类中的函数获取输出并在文本框中显示
嘿,我想在单击按钮时显示函数的输出。我的函数在一个类中,我想在GUI的文本框中显示输出。谁能帮我一下这是功能代码。例如,我想从draw函数中显示python tkinter如何从类中的函数获取输出并在文本框中显示,python,Python,嘿,我想在单击按钮时显示函数的输出。我的函数在一个类中,我想在GUI的文本框中显示输出。谁能帮我一下这是功能代码。例如,我想从draw函数中显示 from random import shuffle class spilastokkur(): def __init__(self): self.spil=[] self.bord=[] self.hond=[] def shuffle(self): spil= self.spil sort = ['H
from random import shuffle
class spilastokkur():
def __init__(self):
self.spil=[]
self.bord=[]
self.hond=[]
def shuffle(self):
spil= self.spil
sort = ['H', 'S', 'T', 'L']
num = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13',]
for i in range(0,4):
for j in range(0, 13):
spil.append(sort[i]+ num[j])
shuffle(spil)
#print spil
return spil
def draw(self):
hond = self.hond
spil = self.spil
if len(hond) >= 3:
print 'Geturu fjarlaegt spil????'
if len(spil) > 0:
x = spil.pop(0)
hond.append(x)
print(hond)
else:
y = hond.pop(0)
hond.append(y)
print hond
output.insert(hond.get())
if len(hond)<=2:
print 'winner'
def sort_cheat(self):
hond = self.hond
if len(hond) >= 4:
del hond[-2]
del hond[-2]
print hond
print 'You got rid of 2 cards. You can do better :)'
enter code here
def number(self):
hond = self.hond
if len(hond) >= 4:
if (hond[-1][1]== hond[-4][1]):
del hond[-4:]
print hond
else:
print 'You are cheating'
以及调用draw函数的按钮
#Buttons
Draw_button = Button(command=s.draw).pack()
#ignore
您可以尝试以下方法: 让draw函数使用所需字符串调用输出的插入方法
output.insert(END, string)
因此,您可以执行以下操作,而不是打印“获胜者”:
output.insert(END, "Winner")
语法:
insert(index [,string]...)
This method inserts strings at the specified index location.
信息和更多
insert(index [,string]...)
This method inserts strings at the specified index location.