这是我关于堆栈溢出的第一篇文章。在谷歌搜索信息一整天后,我整理了我的第一个 python Tkinter 软件。当我运行我的第一个软件时,令我非常沮丧的是,tkinter 一直在思考它自己,没有产生任何错误或显示任何东西。我决定在堆栈溢出时发布我的代码。
请阅读我的 Python 代码 # 解释 Python 的工作原理:
#load the normal drivers
import Tkinter
from Tkinter import *
import Tkinter as tk
import tkMessageBox
from PIL import Image, ImageTk
from Tkconstants import *
# this makes the master app window
master = Tk()
master.geometry('+0+0')
master.wm_title("App Window")
frame = Frame(master, height=300, width=700, background="black")
frame.pack_propagate(0)
#intro image on the right column
img = ImageTk.PhotoImage(file="1.gif")
panel = tk.Label(master, image = img).grid(row = 1, column = 2)
#code to put Buttons into the left column Label
panel2 = tk.Label().grid(row = 1, column = 1)
#onClick commands I will work on Later.
def onClick1():
master.image = PhotoImage(file="captain_scarlett.gif")
w = Label(master, image=master.image)
w.photo = master
w.pack(side=RIGHT)
def onClick2():
photo = PhotoImage(file="1.gif")
w = Label(master, image=photo)
w.photo = photo
w.pack(side=RIGHT)
def onClick3():
photo = PhotoImage(file="1.gif")
w = Label(master, image=photo)
w.photo = photo
w.pack(side=RIGHT)
def onClick4():
photo = PhotoImage(file="1.gif")
w = Label(master, image=photo)
w.photo = photo
w.pack(side=RIGHT)
#these are the Buttons that go into left column
master.Button1 = Button(panel2, text="captain_scarlet", fg="#000",
width=17, background="yellow", command=onClick1)
master.Button2 = Button(panel2, text="Page 2", fg="#000", width=17,
background="yellow", command=onClick2)
master.Button3 = Button(panel2, text="Page 3", fg="#000", width=17,
background="yellow", command=onClick3)
master.Button4 = Button(panel2, text="Page 4", fg="#000", width=17,
background="yellow", command=onClick4)
#normal exiting commands
frame.pack()
master.mainloop()
我得到的答案改变了我对 Tkinter 如何工作和形成的整体理解。