Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Avoiding { in tkinter label coming from tuple

So I moved from printing my results to displaying them via a tkinter label.

ttk.Label(root, text = (‘Erlaubte Fehlergrenze zwischen’, hin1,’ und ‘, hin2,’ = ‘,fehlergrenze,’ Wir haben: ‘, fehler)).pack()

Now I have the problem that I get unwanted brackets {} seemingly coming from ”.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Example for a current output: {Erlaubte Fehlergrenze zwischen} 0100042 { und } 0100047 { = } 2.83 { Wir haben: } 2.78

I am thinking the problem here is that I am trying to display a tuple instead of a string, so I decided to convert it into a string and display it which doesnt seem too smart either.

Maybe there is an easier/better option to just avoid those brackets?

Thanks in advance.

Example for a wanted output: Erlaubte Fehlergrenze zwischen 0100042 und 0100047 = 2.83 Wir haben: 2.78

>Solution :

Does this help? Using f-strings in Python 3.6 and later.

Code:

from tkinter import ttk
import tkinter as tk

root = tk.Tk()

hin1 = '0100042'
hin2 = '0100047'
fehlergrenze = 2.83  
fehler = 2.47
ttk.Label(root, text = f'Erlaubte Fehlergrenze zwischen {hin1 } und { hin2} = { fehlergrenze } Wir haben:{fehler}').pack()

root.mainloop()

Output image:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading