def show():
file = raw_input("What is the name of the image file? ")
picture = Image(file)
width, height = picture.size()
pix = picture.getPixels()
Run Code Online (Sandbox Code Playgroud)
我正在尝试编写代码来显示此图像,但此代码不提供图像.如何更改我的代码才能显示此图像?
我必须创建一个程序,从命令行读取文件并将其转换为ASCII艺术.我使用的是PPM格式,这里是项目的链接.
这是我到目前为止:
import sys
def main(filename):
image = open(filename)
#reads through the first three lines
color = image.readline().splitlines()
size_width, size_height = image.readline().split()
max_color = image.readline().splitlines()
#reads the body of the file
pixels = image.read().split()
red = 0
green = 0
blue = 0
r_g_b_value = []
#pulls out the values of each tuple and coverts it to its grayscale value
for i in pixels:
if i != "\n" or " ":
if len(i) == 3:
red = int(i[0]) …Run Code Online (Sandbox Code Playgroud) 如何给panel1添加背景图片?有哪个命令?
代码:
import wx
import wx
appy=wx.App()
class cg(wx.Frame) :
def __init__(self,parent,id) :
wx.Frame.__init__(self,parent,id,'GPA',pos=(1000,600),size=(600,400))
#splitter = wx.SplitterWindow(self, -1)
panel1 = wx.Panel(self)
panel2 = wx.Panel(panel1, -1,size=(600,200),style=wx.BORDER_SUNKEN)
panel3 = wx.Panel(panel1, -1,pos=(0,200),size=(600,200),style=wx.BORDER_SUNKEN)
#panel3=wx.panel(panel1,-1,pos=(300,200),size=(600,200),style=wx.BORDER_SUNKEN)
#panel13 = wx.Panel(panel1, -1, style=wx.BORDER_SUNKEN)
#panel13 = wx.Panel(panel1, -1, style=wx.BORDER_SUNKEN)
#panel13 = wx.Panel(panel1, -1, style=wx.BORDER_SUNKEN)
#button1=wx.Button(panel1,label='exit',pos=(10,10),size=(10,10))
#self.cnt1=wx.TextCtrl(panel1,pos=(40,60),size=(120,30))
if __name__=='__main__' :
app=wx.PySimpleApp()
frame=cg(parent=None,id=-1)
frame.Show()
app.MainLoop()
Run Code Online (Sandbox Code Playgroud)