Keep getting error displaying Image - python

I'm working on adding an image to a GUI interface using Tkinter. In order to eliminate as many factors as possible, I have stripped out everything but the parts relevant to adding an image, yet it still errors out with "tclError:image "pyimageX" doesn't exist" (where X a number). I have followed directly from a tutorial, and I've checked and double checked the file name, and that the file is directly inside the same folder as the program. I have no other ideas to check, and thus, here I am. Thanks for any help you can provide, I'm really hoping I'm not missing anything obvious.
Here's the snippet that's not working:
from tkinter import *
root =Tk()
versionNumRaw = PhotoImage(file="versionNum.gif")
versionNum = Label(root,image=versionNumRaw)
versionNum.pack()
root.mainloop()
Forgive me, as I know this sort of error has been posted before, with answers that have worked for others, but me, still being not having much experience with programming, cant figure out how to apply the answers others have gotten to my own case.

Related

Cannot run python in VS Code

Edit: TL;DR: Not the Code itself is the problem, the error message is. (Look at the picture/link)
I'm new to programming. Straight to the point: I cannot run my program because of "& cannot be processed syntactically at this point" and i really don't know how to fix it. I already tried a new debugger, reinstalled all expansions, uninstalled VS Code with everything and reinstalled it "clean"... and it still won't work. I searched for hours now... and I still didn't find a solution to this problem.
Btw.: I had first written the whole program on my calculator in math class and it worked perfectly fine, after that I copied it in into VS Code and now it doesn't work. The calculator uses MicroPython v1.9.4
The code, if it's needed, I originally tried (and where the same probleme occurs) is:
import math
def v(a1,a2,a3,b1,b2,b3):
ma=a1*b1+a2*b2+a3*b3
if ma==0:
print("Orthogonal")
m1=math.sqrt(a1**2+a2**2+a3**2)
m2=math.sqrt(b1**2+b2**2+b3**2)
cosg=ma/(m1*m2)
g=math.acos(cosg)/math.pi*180
if g>90:
g=180-g
print(g)
x=a2*b3-a3*b2
y=a3*b1-a1*b3
z=a1*b2-a2*b1
print("N(",x,"|",y,"|",z,")")
As I said: I'm new and I'm very excited to learn programming and all around it. So i would be very thankful if someone can help me.
View of an easy probleme, where the same error occurs

How do I re-obtain code of a still running fuction in Colaboratory?

a total beginner here. By being dumb, I accidentally deleted a function I have been working on for almost 2 hours and then overwrote the undo possibility. The previous version of the function is still active (I can call it) and I was wondering whether there is a way to recover the code or if I have to start all over again. I couldn't find an answer online so I came here.
Thank you in advance for any answers.
Did some more searching and found a similar question which presented a solution.
import inspect
inspect.getsource(function)
Using this I managed to get the source code back as a string with \n formating. Although setting such a code is going to take a while, it is definitely faster than rewriting it.
However, I wonder if perhaps there is a different or better solution.

Condensing python code for creating tkinter widgets

I have a program that I'm designing to teach myself Python but have gotten stuck. I've run across a way to condense python code using % and a list of arguments to have it run as code and looping through the list of arguments until it's done, but can't seem to find it in the documentation or with Google, mostly because I can't figure out how to search for it (sadly it's pretty vague I know).
Mostly what I'm trying to do is prevent having to write approx. 300 lines simply for GUI buttons, labels, frames, ect. with very few changes between them.
Obviously the code is huge so it's all available at Github, github.com/kari-fox/MixxMaster. I'm looking for any kind of recommendations for condensing all of the GUI elements, mostly because I find myself copy/pasting any time I need to make minor changes to any of the similar pieces.
Thanks to Steven Summers in the comments for mentioning classes. I had no idea they were so powerful! I found this guide (https://jeffknupp.com/blog/2014/06/18/improve-your-python-python-classes-and-object-oriented-programming/) and it made understanding and implementing classes work perfectly! That helped me cut out almost 100 lines of purely window-building code and let me do a few sneaky things besides. If anyone wants to see the full implementation check out the github link in the question.

Code Assist in RopeVim...how do you use it?

It is not obvious to me how to use RopeVim's code assist feature.
I was using Vim at the terminal in mac os x.
I moved to MacVim and the GUI does help b/c I do see a Ropevim menu option now.
I have Ropevim set up correctly I'm fairly sure.
I want to test the code assist feature out, so I type in self.asser
and nothing happens. I've tried tab and control + space.
I sometimes see basically a history of what I've typed, more along the lines of auto-complete, b/c I have a plugin for that, but I want to see that code assist shows me what possible options are.
When I type in from django.contrib.
I want to know if code assist will be able to show me things like mail, syndication, etc, modules that I've never even typed in this project before.
Of course pycharm certainly does this flawlessly, but I am still partial to vim. Can't quite let it go, but most definitely can not afford the time to continue to fiddle with this tinkering b/c I need to get coding. The Rope library seems like it can do what I need: code assist and basic refactoring, but how?
I use jedi-vim and code assist works perfectly. https://github.com/davidhalter/jedi-vim.
Update:
I uploaded a short video. http://youtu.be/5lgbV8iY8-Q
Did you look at the code? Code assist seems to be mapped to <M-/>.

IDA pro Imports

i have been delving into ida Pro for the last couple of weeks to get a bit of a background.
Something that has been bugging me for a long time though is the seemingly lack of support for pulling out the imported functions.
All i want is a script that can copy the entire imports window and paste into a text file, but I am having serious trouble finding anything in the API's that can help me do this. It should be very simple, yet I find it impossible. I have managed to find things to pull out the library's from this window, but nothing to pull out everything.
any help or direction would be much appreciated.
I agree with the assertion that you should use Ctrl+Ins or dumpbin.
However, what you ask has been solved already by the IDAPython project and I suggest you head over and look at their examples (here and here), especially this one.
The relevant idaapi functions are:
idaapi.get_import_module_qty
idaapi.enum_import_names
GUI Solution:
You can copy the entire contents of the imports window by placing focus on that window and hitting Ctrl+Ins.
IDAPython Solution:
This may need to be tweaked to your liking, but this should hopefully get you started:
text = ""
seg = SegByName(".idata")
for i in xrange(seg, SegEnd(seg), 4):
text += "%08x %s\r\n" % (i, Name(i))
open(r"c:\imports.txt", "wb").write(text)

Categories