如何让GUI打印标签中的C和D,而不是{C和D}?Python Tkinter
在GUI上,当代码选择“C和D”时,标签上的输出看起来像{C和D}。有没有办法把{}去掉,把C和D打印出来?最好不必向列表中添加更多元素如何让GUI打印标签中的C和D,而不是{C和D}?Python Tkinter,python,tkinter,Python,Tkinter,在GUI上,当代码选择“C和D”时,标签上的输出看起来像{C和D}。有没有办法把{}去掉,把C和D打印出来?最好不必向列表中添加更多元素 from tkinter import * root= Tk() root.title('Letters') def test(): import random letter=['A','B','C and D'] letterslist=list() count = 0 while count <5:
from tkinter import *
root= Tk()
root.title('Letters')
def test():
import random
letter=['A','B','C and D']
letterslist=list()
count = 0
while count <5:
y= random.choice(letter)
letterslist.append(y)
count=count+1
return letterslist
x=test()
label1 =Label(root, text = x , fg="White", bg="Orange" )
label1.pack()
root.mainloop()
从tkinter导入*
root=Tk()
root.title('字母')
def test():
随机输入
字母=['A'、'B'、'C和D']
字母列表=列表()
计数=0
当count时,您可以将列表中的所有元素连接到:
return ' '.join(letterlist)
您的代码现在看起来像这样
from tkinter import *
root= Tk()
root.title('Letters')
def test():
import random
letter=['A','B','C and D']
letterslist=list()
count = 0
while count <5:
y= random.choice(letter)
letterslist.append(y)
count=count+1
return ' '.join(letterslist)
x=test()
label1 =Label(root, text = x , fg="White", bg="Orange" )
label1.pack()
root.mainloop()
从tkinter导入*
root=Tk()
root.title('字母')
def test():
随机输入
字母=['A'、'B'、'C和D']
字母列表=列表()
计数=0
当计数时,请执行以下操作:
from tkinter import *
root= Tk()
root.title('Letters')
def test():
import random
letter=['A','B','C and D']
letterslist=list()
count = 0
S=""
while count <5:
y= random.choice(letter)
letterslist.append(y)
count=count+1
S=S+str(y)
if count !=5:
S=S+","
print (S, letterslist)
return S
x=test()
label1 =Label(root, text = x , fg="White", bg="Orange" )
label1.pack()
root.mainloop()
从tkinter导入*
root=Tk()
root.title('字母')
def test():
随机输入
字母=['A'、'B'、'C和D']
字母列表=列表()
计数=0
S=“”
当计数返回''时,加入(字母列表)
或返回''。加入(字母列表)
可能重复的