It is a great toolkit for checking your code base against coding style (PEP8), programming errors like “library imported but unused”, “Undefined name” and code which is not indented. It can also look for certain type errors, it can recommend suggestions about how particular blocks can be refactored, and can offer you details about the code’s complexity.įlake8 is a Python library that wraps PyFlakes, pycodestyle and Ned Batchelder’s McCabe script. It tries to enforce a coding standard and looks for code smells. Pylint is a tool that checks for errors in Python. Most Python developers enjoy using Pylint or Flake8 to check their code for errors and style guides. It is also just really horrible to look at. It makes it easy to spot bugsīadly formatted code can make it really, really hard to spot bugs or even to work on a program. Otherwise it becomes harder to work together. Several people will likely be working on the same software project and code you write must be understood by your teammates. Team supportįormatting your code becomes more important when you are working in a team. If you forget to do that formatting you might lose your job prospects, just because of your poorly formatted code. When you're in a coding interview, sometime the interviewers will care if you’re formatting your code properly. It looks more organized, and when someone looks at your code they'll get a good impression. Why formatting your python code is important Readabilityįormatting your code will help you read your code efficiently. The difference between working on well-formatted code and working on badly formatted code is like the difference between living in a palace and living in a dirty house. At some point (around 15,000 lines of code), it becomes harder to understand the code that you yourself wrote. If you write a small program (with 1000 lines of codes) you can probably get away without formatting your code.īut as programs get more and more complex, they get harder and harder to understand. Junior programmers often focus on making sure their code is working and forget to format the code properly along the way. Writing Python code is one thing and writing the code in a good format is another thing. Path = "D:\Documents\Background.png" # Get the image full pathīackgroundLabel = Label(parent,image=img)īackgroundLabel. Self.canvas = Canvas(root,width=canvasWidth,height=canvasHeight) Img = ImageTk.PhotoImage(load) # convert the load to PhotoImage Now use it : path = "C:/./img.png" # Get the image full path Now get your full path image like: C:/./img.png When you have it use it like: from PIL import Image, ImageTk # import image so you can append the path and imagetk so you can convert it as PhotoImage If use any types of png or jpg and jpeg you can't draw it with just PhotoImage you will need PIL library pip3 install PIL To create a Label: backgroundlabel = Label(parent, image=img) Your code will not working with root.PhotoImage and root.Label. Root is your window Tk() class so you cant Attribute it for PhotoImage because it's dosen't have it so you see AttributeError tkinter.Tk() and tkinter.PhotoImage is a different classes. You are using root to Attribute PhotoImage this is impossible!
0 Comments
Leave a Reply. |