Why won't python use os.startfile after using os.startfile once? - python

I'm creating an application which can jump through tkinter files.
The first one is a login screen which has the following definition:
if results:
os.startfile("data\main.pyw")
with open("data\logdat.txt","w") as text_file:
text_file.write(username.get())
root.destroy()
Next one is the main screen where all the menu options are.
Here is one specific button for a "calculator", so when the button is pressed it opens another tkinter file.
def balancecal():
webbrowser.open(r"data\egyenleg.pyw")
root.destroy()
But when initiating this, it closes the program.
I tried opening the main.py file itself, writing out the "\data" part from the balancecal definition, and with that it opened the file, so the file itself is found.. It just won't work after opening it through the default procedure (with going through the login screen too).
Can someone help me out please?
I'm still a beginner here.
Thanks!

Related

Pygame window wont move or close after using tkinter

I have had this problem for ages now with many different projects now, so I really want to find out how to fix it. For example, in one of my projects, I created a level editor for a game. The level editor had the option to save and load different levels from a file using tkinter.filedialog.
Now after I select the file, the game will still work, but the 'X' close button doesn't work anymore, and I can't move the window.
The game itself works as usual, and I can still interact with everything inside of the window, but I can't move or close the window.
Thanks in advance.
Ok. I figured this one out. The problem went away when I called the tkinter functions from a key press, not a mouse press.

I'm having problems using python on a mac: (Running a program without the idle and Background of tkinter buttons)

I've been having problems running my python program on the mac.
Opening without the IDLE:
Firstly, whenever I open the program it opens with the IDLE by default. I would like it to open with the launcher, but when I tried opening it with the launcher, it came up with a preferences window that had no "Ok", "Next", or "Continue" button.
On Windows, if you open a python program, then by default it will run it with the launcher, causing it to go directly into the program without the user needing to go through any other windows. The .pyw extension can also be used to make it run without the console. How would I set the Mac so that it does this?
Background of tkinter buttons:
In the following function I have a menu with several buttons:
def MainMenu():
Move() # This clears any widgets that are on the screen.
Win.unbind("<Up>") # Win is the name of my window.
Win.unbind("<Down>")
Win.unbind("<Return>")
Win.config(bg="#FFFF00")
try:Welcome=GUI.Label(Win,text="Welcome "+Name+("."if Name[-1]!="."else"")+"\nYou should have £"+str(Cash)+("0"if str(Cash)[-2]=="."else"")+".\n What would you like to do?",bg="#FFFF00") # GUI is the variable containing the tkinter library.
except IndexError:Welcome=GUI.Label(Win,text="Welcome "+Name+".\nYou should have £"+str(Cash)+".\n What would you like to do?",bg="#FFFF00")
Welcome.place(x=0,y=0)
ManualButton=GUI.Button(Win,text="Manual adjustment.",width=96,height=4,command=ManualChange,bg="#FFFF00")
ManualButton.place(x=0,y=0)
RecButton=GUI.Button(Win,text="Recall.",width=96,height=4,command=Recall,bg="#00FF00")
RecButton.place(x=0,y=0)
Setti=GUI.Button(Win,text="Settings",command=Settings,bg="#FFFF00",width=96,height=4)
Setti.place(x=4,y=4)
if Set:
RecoButton=GUI.Button(Win,text="Record spending.",width=96,height=4,command=Spending,bg="#FF80C0")
RecoButton.place(x=256,y=14)
Win.update_idletasks()
Welcome.place(x=Win.winfo_width()//2-Welcome.winfo_width()//2,y=16)
ManualButton.place(x=Win.winfo_width()//2-ManualButton.winfo_width()//2,y=256)
RecButton.place(x=Win.winfo_width()//2-ManualButton.winfo_width()//2,y=192)
if Set:RecoButton.place(x=Win.winfo_width()//2-ManualButton.winfo_width()//2,y=128)
Setti.place(x=Win.winfo_width()//2-ManualButton.winfo_width()//2,y=340)
Win.update()
Here is a picture of the menu it creates (Name="S", Cost=8805.33, Set=True):
This is what it looks like on a Mac (Name="S", Cost=96, Set=True):
I would like to make the buttons look more like they do on Windows, or at least get rid of the grey space around the buttons. Does anyone have any idea how I'd do this?

Selenium::Python::Pop Up Window

I am trying to automate some basic web browser manipulation. As part of this sequence there is a popup window that must be dealt with. Once the python code the causes the popup window to appear happens, no other code past that point will run until I manually close that window. Then all remaining code runs fine.
I've try this below to try to deal with handling the popup but to no avail:
for handle in browser.window_handles:
print "Handle = ",handle
browswer.switch_to_window(handle);
elem=browser.find_element_by_tag_name("title")
print elem.get_attrbitue("value")
I cannot even get a basic 'print' command to execute until I close the popup window. Is there a need to set some type of event handler BEFORE the code is called that brings the popup menu?
Thanks for any suggestions.

tkinter: Help fixing photo image error created when same window opened twice

I think I've pretty much narrowed down the problem, so I'll put it out here:
I made a change to the program I am working on. The change makes a certain tkinter window reopen when an error occurs. This was done by moving it to a function, and having the script call the function if it needed to. This solved users having to restart the program.
All the windows in my program have an icon that is called and implemented in every window using the following lines:
Thumbnail = PhotoImage(file = "C:\\Users\\Owatch\\Pictures\\NetSendClient\\files\\GIF\\TK_ICON.gif")
Window.tk.call("wm","iconphoto",Window._w, Thumbnail)
This works fine for every single window across the program. However, it continues to generate an error when the same window is called to open a second time.
Error:
File "C:\Users\Owatch\Documents\Unisung\Produced Content\NetSendClient[0.9]\files\Program_Files\NS[9].py", line 208, in SCN
Window.tk.call("wm","iconphoto",Window._w, Thumbnail)
_tkinter.TclError: can't use "pyimage4" as iconphoto: not a photo image
I'm not sure why this error occurs the second time the window is opened. To give some more information on why it needs to be reopened. When a user presses a button inside this window, it triggers a function that calls the window to be destroyed before it is later reopened. So maybe it's because it's not being cleanly disposed of or something. I don't know. Thanks for helping!
The problem was created by a confliction between multiple windows using the same icon simultaneously.
I cannot go any more specific than that, but the issue was resolved by eliminating temporary and toplevel windows that did not destroy themselves before another opened.
I hope this can be of some assistance to other individuals. I am afraid I cannot provide any more information than this.

Forcing deletion of file. Python, Windows

I am working on a Reset button. The button is supposed to clear the text that is generated in a Text Widget and delete the file that the data was being written to. Clearing the Text Widget works, but I am having problems deleting the file.
When I try to delete it from windows, it says that it is still open in Python. So, I closed it from my code first, and then tried to delete it but didn't work.
I have programmed the other button so that it doesn't override files. So, I can't just delete the data that is already written in the file.
Is there any way that I can force the deletion of that file??
I am using Python 2.6.6.
This is my code on the reset button:
def reset_it(self):
self.run.update() # run is the other button, I have to stop it's processing!
self.Outputlines.update() # Forcing the TextWidget to update.
self.Outputlines.config(state=NORMAL)
self.Outputlines.delete(1.0, END) # Clearing everything from the TextWidget.
self.Outputlines.config(state=DISABLED)
self.run.wait_variable() # Stopping the run button.
self.infile.close() # Closing the file.
os.remove(self.filename.get()) # Code to delete the file.

Categories

Resources