非常に新しいです。ウィンドウとTkinterの操作に興味があります。優しくしてください。PythonでTkinterを使って新しいウィンドウに切り替える手助けがありますか?
ここに私のコードは、新しいウィンドウに移動し、その新しいウィンドウで画像を開くはずです。しかし、新しいウィンドウにイメージを置くのではなく、最初のウィンドウにイメージを置きます。
これはトップレベルと関係があると思いますが、私はそのことを正しく行うようです。
import os
from PIL import Image
from PIL import ImageTk
from Tkinter import Tk
import os
class Application(Frame):
""" A GUI application with three buttons. """
def __init__(self, master):
""" Initialize the frame"""
Frame.__init__(self,master)
self.grid()
self.create_widgets()
def create_widgets(self):
""" Create button, text and entry widgets"""
self.instruction = Label(self, text = "First off what is your name?")
self.instruction.grid(row=0, column =0, columnspan=2, sticky=W)
#self.first = first
self.name = Entry(self)
self.name.grid(row=1, column =1, sticky=W)
self.submit_button = Button(self, text ="Submitsss", command = self.reveal)
self.submit_button.grid(row = 2, column = 0, sticky =W)
self.text = Text(self, width =35, height = 5, wrap = WORD)
self.text.grid(row=3, column = 0, columnspan =2, sticky = W)
self.ok_button = Button(self, text = "Next", command = self.go_to_2)
self.ok_button.grid(row = 2, column = 0, sticky = E)
def reveal(self):
"""Display message based on the name typed in"""
content = self.name.get()
message = "Hello %s" %(content)
self.text.insert(0.0, message)
def go_to_2(self):
self.destroy()
#root = Tk()
#self.newApplication = tk.Toplevel(self.master)
#self.app3 = Application2(self.newApplication)
root.title("game")
root.geometry("600x480")
#root = Tk()
#app2=Application2(root)
self.newWindow = Tk.Toplevel()
self.app = Application2(self.newWindow)
class Application2(Frame):
""" A GUI application with three buttons. """
def __init__(self, master):
""" Initialize the frame"""
Frame.__init__(self,master)
self.grid()
self.create_widgets()
#master.panel()
master.title("a")
#self.root.mainloop()
master.img = ImageTk.PhotoImage(Image.open("C:\Users\david\Pictures\sdf.jpg"))
master.panel = Label(root, image = master.img)
master.panel.pack()
def create_widgets(self):
self.submit_button = Button(self, text ="Submit")
self.submit_button.grid(row = 2, column = 0, sticky =W)
self.name = Entry(self)
self.name.grid(row=1, column =1, sticky=W)
self.ok_button = Button(self, text = "Next", command = self.go_to_3)
self.ok_button.grid(row = 2, column = 0, sticky = E)
def go_to_3(self):
root = Tk()
app2=Application3(root)
#def create_picture(self):
class Application3(Frame):
""" A GUI application with three buttons. """
def __init__(self, master):
""" Initialize the frame"""
Frame.__init__(self,master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.button = Button(self, text = "ass")
root.mainloop()
root = Tk()
root.title("game")
root.geometry("600x480")
app = Application(root)
root.mainloop()
#app2= Application2(root)
#if __name__ == '__main__':
# main()
ありがとう – Daveyman123