+ -
当前位置:首页 → 问答吧 → 急死!!!python tkinter,建立窗口的主函数怎样调用建立窗口的从函数?

急死!!!python tkinter,建立窗口的主函数怎样调用建立窗口的从函数?

时间:2011-01-15

来源:互联网

代码如下,运行出现错误,不知道怎么解决,我希望有个主窗口,然后点击win1、win2按钮弹出两个从窗口
如果删除红色标出的部分,就可以运行,初步确定是canvas.create_image的问题,怎么解决呢?急!!!
from Tkinter import *
def x1():
  root1=Tk()
  canvas=Canvas(root1,
  width=1000,
  height=700,
  bg='gray')

im1=PhotoImage(file='f:/3.gif')
canvas.create_image(0,0,image=im1)
im2=PhotoImage(file='f:/4.gif')
canvas.create_image(500,00,image=im2)
  canvas.pack()
  button=Button(root1,
  text='back',
  font=('Arial',12),
  width=14,
  height=2,
  command=root1.destroy)
  button.place(x=470,y=250)
  root1.mainloop()
def x2():
  root2=Tk()
  canvas=Canvas(root2,
  width=1000,
  height=700,
  bg='orange')

im1=PhotoImage(file='f:/4.gif')
canvas.create_image(0,0,image=im1)
im2=PhotoImage(file='f:/3.gif')
canvas.create_image(50,0,image=im2)
  canvas.pack()
  button=Button(root2,
  text='back',
  font=('Arial',12),
  width=14,
  height=2,
  command=root2.destroy)
  button.place(x=470,y=250)
  root2.mainloop()
root=Tk()
root.title('Test')
frame=Frame(height=300,width=400)
frame.pack()
button1=Button(root,
  text='win1',
  width=14,
  height=1,
  command=x1)
button1.place(x=100,y=150)
button2=Button(root,
  text='win2',
  width=14,
  height=1,
  command=x2)
button2.place(x=300,y=150)
root.mainloop()

作者: auforever888888   发布时间: 2011-01-15

呵呵,确实很急,我自己解决了。哎,菜鸟的日子真难混啊~~~
im1=PhotoImage(file='f:/4.gif')改为
im1=PhotoImage(file='f:/4.gif',master=root1)
添上一个master属性就好了

作者: auforever888888   发布时间: 2011-01-15