英文:
First and Last element of String in brackets when copied to file
问题
Here's the translated content you requested:
<h4>Explanation:</h4>
我有一个名为`text()`的函数,它根据一个变量是`0`还是`1`,将一系列字符串附加到列表`Prüftext`中,并将该字符串复制到我的剪贴板。
我从两个在函数外部定义的列表中获取要附加的字符串。它们是:
```py
SetBlock = ["SetBlock1", "SetBlock2", "SetBlock3", "SetBlock4"]
和:
TextBlock = ["TextBlock1", "TextBlock2", "TextBlock3", "TextBlock4"]
我的问题:
当我将字符串复制到文件中时,第一个和最后一个元素都是这样的:
```plaintext
{SetBlock1} TextBlock1 TextBlock2 {SetBlock3}
```
或者当我在函数中切换列表时,我得到这个:
TextBlock1 {SetBlock1} {SetBlock3} TextBlock2
但我想要的是:
SetBlock1 TextBlock1 TextBlock2 SetBlock3
如果我通过Prüftext.append("手动字符串")
手动附加一个字符串,它也会出现在大括号中。
因此,这似乎与列表以及它们的访问方式有关?
我已经导入了tkinter
作为Tk
。
该函数:
def text(pfVar):
Prüftext = []
dummy = ""
if pfVar == 0:
Prüftext.append(SetBlock[0])
if pfVar == 1:
Prüftext.append(SetBlock[1])
for i in range(0, len(Indicator)):
if Indicator[i] == 1:
Prüftext.append(TextBlock[i])
if kosten == -1:
Prüftext.append(SetBlock[3])
if kosten == 1:
Prüftext.append(SetBlock[2])
if kosten == 0:
dummy = dummy
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append(Prüftext)
r.update()
r.destroy()
print(Prüftext)
我查看了tkinter
文档并尝试更改SetBlock
和TextBlock
中的文本,但没有找到我认为会对我有所帮助的内容。
Please note that certain characters like `ü`, `ö`, and `ß` have been retained in the translation.
<details>
<summary>英文:</summary>
<h4>Explaination:</h4>
I have a function `text()`, which is to append a series of strings to the list `Prüftext`, depending on if a variable is `0` or `1`, and copy that string into my clipboard.
I get the strings which are to be appended from two lists, that are defined outside of the function.
These are:
```py
SetBlock = ["SetBlock1","SetBlock2","SetBlock3","SetBlock4"]
and:
TextBlock = ["TextBlock1","TextBlock2","TextBlock3","TextBlock4"]
<hr>
<h4>My Problem:</h4>
When I copy the string into a file, the first and last elements are in curly brackets like this:
{SetBlock1} TextBlock1 TextBlock2 {SetBlock3}
Or when I switch out the lists in the function I get this:
TextBlock1 {SetBlock1} {SetBlock3} TextBlock2
But I want:
SetBlock1 TextBlock1 TextBlock2 SetBlock3
If I append a string after "manually" by doing Prüftext.append("manual string")
, it is also in curly brackets.
So it seems to be related in some kind to the lists and how they are accessed?
I have imported tkinter
as Tk
<hr>
<h4>The function:</h4>
def text(pfVar):
Prüftext = []
dummy = ""
if pfVar == 0:
Prüftext.append(SetBlock[0])
if pfVar == 1:
Prüftext.append(SetBlock[1])
for i in range(0, len(Indicator)):
if Indicator[i] == 1:
Prüftext.append(TextBlock[i])
if kosten == -1:
Prüftext.append(SetBlock[3])
if kosten == 1:
Prüftext.append(SetBlock[2])
if kosten == 0:
dummy = dummy
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append(Prüftext)
r.update()
r.destroy()
print(Prüftext)
I have looked at the tkinter
documentation and tried to change out the text in the lists SetBlock
, and TextBlock
but didn't find anything that I think would help me.
答案1
得分: 1
尝试将 r.clipboard_append(Prüftext)
更改为 r.clipboard_append(", ".join(Prüftext))
。
英文:
Try to change r.clipboard_append(Prüftext)
to r.clipboard_append(", ".join(Prüftext))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论