Python PySimpleGui Output Title Bar Name Problem

  • Thread starter Thread starter Arman777
  • Start date Start date
  • Tags Tags
    Output
Click For Summary
The discussion centers around using PySimpleGUI to display various astronomical calculations in pop-up windows. The user initially encounters an issue where the content of the pop-up becomes the title bar's name. A solution is provided, suggesting the use of the 'title' keyword in the sg.popup function to customize the title. The user then seeks advice on how to format multiple pieces of information in a single line within the pop-up. The solution involves using string formatting techniques, specifically the '%' operator, to concatenate text and variables without line breaks. This approach successfully resolves the user's formatting concerns.
Arman777
Insights Author
Gold Member
Messages
2,163
Reaction score
191
Python:
import PySimpleGUI as sg
print("The age of the universe is", age_of_universe, "Gyr")
print("The age of universe at z = ", z, "is", age_of_universe_at_z,)
print("Lookback time is", lookback_time , "Gyr")
print("Comoving distance to an object at z =", z , "is" , comoving_distance, "Mpc")
print("Luminosity distance to an object at z =", z, "is", luminosity_distance, "Mpc")
print("Angular diameter distance to an object at z =", z, "is", angular_distance, "Mpc")

I tried to use the popup method. However this time the thing that written inside the popup becomes the name of the title bar

Python:
   sg.popup('This is the modified LightGreen3 Theme', 'It has black button text')

1575636600821.png


So how can I print these things and can name the title bar whatever I want.

Thanks.

Note: I can accept solutions offered by using tkinter but I prefer pysimpleguı
Note 2: Also there are some variables inside the print statements. So that's also important
 
Last edited:
Technology news on Phys.org
Did you try going to the documentation? You just need to add a title keyword
Python:
sg.popup('This is the modified LightGreen3 Theme', 'It has black button text', title='MyTitle')
 
  • Like
Likes Arman777
phyzguy said:
Did you try going to the documentation? You just need to add a title keyword
Python:
sg.popup('This is the modified LightGreen3 Theme', 'It has black button text', title='MyTitle')
Yes kind of but appreantly I missed it.

Okay that works. Thanks. But I also want to ask something else. Do you have idea how can I print one statement in single line ?
For instance If I write something like this,

Python:
import PySimpleGUI as sg

z = 12
sg.popup("The age of the universe is",z,"Gyr", title="CoSmoS")

1575642427304.png


Which is not a good way to show the output. The problem is everytime I put "," between the text and data itseld it goes to new line. How I can print each stament in one line ?
 
You need to learn to use formatting:
Python:
import PySimpleGUI as sg
z=13.8
sg.popup("The age of the universe is %.2f Gyr"%z, title="MyTitle")
 
  • Like
Likes Arman777
phyzguy said:
You need to learn to use formatting:
Python:
import PySimpleGUI as sg
z=13.8
sg.popup("The age of the universe is %.2f Gyr"%z, title="MyTitle")
I know that format but I never use it. But it seems working in this case. Thanks a lot :)
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 22 ·
Replies
22
Views
7K
  • · Replies 40 ·
2
Replies
40
Views
5K