I use python on Ubuntu, and I am (as my name suggests) a complete noob at it all. I want to insert a very basic image, I have looked around, copied coding etc, but mothing seems to work. I want to insert an image, nothing else, so it just appears on the screen when I run it in shell. Please help? and please explain in simple terms, i'd like to know what I'm actually doing! Thank-you in advance.
you can install PIL imagemagick
then:
import Image
im = Image.open("your_image")
im.show()
I would try something like:
import webbrowser
webbrowser.open('file:///path/to/my/file.jpg')
Related
I want to make canvas and user will draw some picture in that which I want to save as Image. I am using Python 3.3.2. It doesn't support PIL or Image module. Can someone guide me on this..?
Thanks.
Maybe it's a bit too late to answer this question. But, I'll still go ahead.
from tkinter import *
import pyscreenshot as ImageGrab
r=Tk()
canvas = Canvas(r,height=1000,width=2000,bg="snow")
def getter():
x2=r.winfo_rootx()+canvas.winfo_x()
y2=r.winfo_rooty()+canvas.winfo_y()
x1=x2+canvas.winfo_width()
y1=y2+canvas.winfo_height()
print("save")
ImageGrab.grab().crop((x2,y2,x1,y1)).save("./test.jpg")
b1=Button(r,text="Save",command=lambda:getter())
b1.grid()
Let me know if this doesn't work. Hope it helps..
I'd like this Python script to run through my webhost/domain. That way maybe I can put a hyperlink on my index that leads to this for a little display?
I would like this to be played in the tab
import turtle
bob = turtle.Pen()
for i in range(700):
bob.forward(i)
bob.left(80)
bob.forward(50)
bob.right(i)
bob.back(50)
bob.left(i)
This is a very old question but since someone else just found it and posted a response, maybe others are searching for this functionality as well.
If you are just looking to share your turtle code with others and show its output, Repl.it can do this for you.
Live demo of your code here
I had an idea for a program I want to write for my boss at work. My idea was that I was going to load a template into python, run through a .txt file and fill the template with the corresponding information using the graphics library.
My only problem is I don't know how to save the final result. Some of my colleagues in a python class I took a year ago did it and now I regret not asking how... Any help will be appreciated. Thanks.
You can use Selenum for this purpose.
Selenium using a webdriver provides the facility to take screenshots!
from selenium import webdriver
driver = webdriver.Firefox()
# code goes in here
driver.save_screenshot(title+".png")
I believe this will serve your purpose!
Hope it helps.
TO take screenshots you can use pyscreenshot module.
import pyscreenshot as ImageGrab
im=ImageGrab.grab()
im.show()
Here im variable is the image of the screenshot
Source: https://pypi.python.org/pypi/pyscreenshot
I was making a python project that could play online games and i had a problem. I wanted to make the computer create a user but to do so you had to write in a name. I tried using ctypes but that didnt work out because i couldnt find any way to write letters, only click and move the cursor. Does anyone know a way to make python take control over keyboard? I am thinking something like this:
import ctypes
import webbrowser
webbrowser.open("www.url.com")
ctypes.key.a()
ctypes.key.c()
ctypes.key.c()
ctypes.key.enter()
I would recommend pyautogui. It is as simple as pyautogui.press('b').
I was wondering if anyone knows how to import a sprite and let it move when pressing the arrow keys in python, without using pygame, or some other library. This is purely out of curiosity, because I was just thinking about some sort of personal challenge, and that's what came to mind: a python game, without the help of pygame or libtcod. Is this possible, or do you need a library to do this for you? I'd appreciate anyone's input on this one.
Thanks.
What comes to my mind is using Tkinter's Canvas class. It is quite possible to do a simple program like that described using bindings on this class.
A good example of this may be found in Mark Lutz's Programming Python (http://shop.oreilly.com/product/9780596158118.do), the Moving Pics example.
If you don't own this, you can still look at the code for it as a reference by downloading the code using the link on the right side of the page. The path to the appropriat folder is /PP4E-Examples-1.3.1/Examples/PP4E/Gui/MovingPics/.