0

Code: from tkinter import * from webbrowser import *

def opnbk1():
    open('https://www.goodreads.com/Harry_Potter_and_the_Sorcerer_s_Stone?ac=1&from_rank=1')

def test():
    Bk= Tk()
    bk1 = PhotoImage(file='HP.png')
    book1 = Button(Bk,image=bk1,command=opnbk1,bg='white').place(relx=0,rely=0)
    Bk.mainloop()

test()#This function call works,but inside the window root, it does not.
root=Tk()
b2 = Button(root, text='Click Me', command=test).place(relx=0.167, rely=0.9)
root.mainloop()

Thank you!

EarlGrey
  • 531
  • 7
  • 29
Siva A
  • 21
  • 2
  • 1
    Hi Siva! You should include all possible details about your problem. If you can copy/paste the full error message, it could be helpful as well. Good luck! – elersong Jul 08 '20 at 06:24
  • File "/usr/lib/python3.8/tkinter/__init__.py", line 2645, in __init__ Widget.__init__(self, master, 'button', cnf, kw) File "/usr/lib/python3.8/tkinter/__init__.py", line 2567, in __init__ self.tk.call( _tkinter.TclError: image "pyimage2" doesn't exist – Siva A Jul 08 '20 at 06:27
  • 1
    It is because you have multiple instances of `Tk()`. Change `Tk()` to `Toplevel()` inside `test()` or `PhotoImage(master=Bk, file='HP.png')`. – acw1668 Jul 08 '20 at 06:42
  • @Siva A. Your code is working. – toyota Supra Apr 26 '23 at 12:14

0 Answers0