First and Last element of String in brackets when copied to file

huangapple go评论60阅读模式
英文:

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文档并尝试更改SetBlockTextBlock中的文本,但没有找到我认为会对我有所帮助的内容。


Please note that certain characters like `ü`, `ö`, and `ß` have been retained in the translation.

<details>
<summary>英文:</summary>

&lt;h4&gt;Explaination:&lt;/h4&gt;

I have a function `text()`, which is to append a series of strings to the list `Pr&#252;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 = [&quot;SetBlock1&quot;,&quot;SetBlock2&quot;,&quot;SetBlock3&quot;,&quot;SetBlock4&quot;]

and:

TextBlock = [&quot;TextBlock1&quot;,&quot;TextBlock2&quot;,&quot;TextBlock3&quot;,&quot;TextBlock4&quot;]

<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&#252;ftext.append(&quot;manual string&quot;), 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&#252;ftext = []
    dummy = &quot;&quot;

    if pfVar == 0:
        Pr&#252;ftext.append(SetBlock[0])

    if pfVar == 1:
        Pr&#252;ftext.append(SetBlock[1])

    for i in range(0, len(Indicator)):
        if Indicator[i] == 1:
            Pr&#252;ftext.append(TextBlock[i])

    if kosten == -1:
        Pr&#252;ftext.append(SetBlock[3])

    if kosten == 1:
        Pr&#252;ftext.append(SetBlock[2])

    if kosten == 0:
        dummy = dummy

    r = Tk()
    r.withdraw()
    r.clipboard_clear()
    r.clipboard_append(Pr&#252;ftext)
    r.update()
    r.destroy()

    print(Pr&#252;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&#252;ftext) 更改为 r.clipboard_append(&quot;, &quot;.join(Pr&#252;ftext))

英文:

Try to change r.clipboard_append(Pr&#252;ftext) to r.clipboard_append(&quot;, &quot;.join(Pr&#252;ftext))

huangapple
  • 本文由 发表于 2023年5月21日 03:13:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76296956.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定