0

I am trying to write a Bash script so that I can run my program on a double click. The program uses tkinter and the GUI is the only thing I need to see. My bat file is the following:

python BudgetGUI.py &

This runs the code and successfully prints any print statements I have throughout my code but it never opens up the GUI. It simply runs through and closes immediately.

How can I modify the bash script to run the GUI?

Thanks in advance!

Edit Solutions for both mac and pc would be great, though at the moment I am on PC. I am working in Python3.

2 Answers 2

1

You need to add a call to mainloop(). I can't say for sure without seeing your code, but probably you need to add root.mainloop() to the bottom.

You don't need a bash or bat file. For your mac, just add a shebang and make the file executable. For Windows, add a shebang and associate the file with py.exe.

If you want to suppress the command line from popping up along with the GUI, rename your file with a .pyw extension.

Sign up to request clarification or add additional context in comments.

10 Comments

So...one problem I have is that my code doesn't use any classes. I am still pretty fuzzy on object oriented programming so I sort of just forced it work without using classes. If I run the script from IDLE, the GUI and shell pop up fine. Any workarounds to this or did I dig myself into a hole?
classes have nothing to do with this
Oh. I guess I was confused. I don't have "root.mainloop()" in my code yet it still runs. If I simply added that to the end of my script, how could I implement what you are suggesting?
IDLE cheats and adds that line for you (sorta). Outside of IDLE you need to add it yourself.
As I said, you need to associate the file with py.exe. Currently it's associated with IDLE. I think you can set that in the "open with" dialog.
|
0

Make the window made with tkinter stay out of IDLE*

if you have

root = Tk()

at the end put

root.mainloop()

if you have another name for that like:

window1 = Tk()

then, at the end put

window1.mainloop()

and so for any name you gave to the istance of Tk()

A little example

import tkinter as tk

class Window:
    root = tk.Tk()
    label = tk.Label(root, text = "Ciao").pack()


app = Window()
app.root.mainloop()

Python 2

The code above is for python 3. For python 2 you just need to change the first line (Tkinter with T, not t)

import Tkinter as tk

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.