我正在开发一个基于Python的GUI,我有以下问题:我想把图片放在窗口的顶部,把按钮放在它的正下方。我使用的是Tkinter模块,无论我使用什么几何图形(放置、打包或网格),按钮都不会移动。仅当我使用网格将图像移动到第1行(第二行)时才会显示,否则根本不会显示。这是我现在使用的代码。作为参考图片有291x87像素的尺寸。你知道吗
import Tkinter
from Tkinter import *
def main():
window =Tk()
window.geometry("300x300")
window.title("Dienes Blocks Application")
window.iconbitmap(default='favicon.ico')
app = HomeScreen(window)
window.mainloop()
class HomeScreen(Frame):
def __init__(self, master):
Frame.__init__(self,master)
self.create_buttons()
self.sparx_head()
def sparx_head(self):
self.grid()
photo = Tkinter.PhotoImage(file="logosmall.gif")
sparx_header = Label(image=photo)
sparx_header.image = photo # keep a reference!
sparx_header.grid(column=0, row=0, columnspan=2, rowspan=2, sticky='NSEW')
def create_buttons(self):
self.grid()
#teacher button
teacher_button = Tkinter.Button(self, text="Teacher")
teacher_button.grid(column=0, row=10)
# student button
student_button = Tkinter.Button(self, text="Student")
student_button.grid(column=2, row=10)
# prototype button
prototype_button = Tkinter.Button(self, text="Prototype")
prototype_button.grid(column=1, row=10)
if __name__ == "__main__":
main()
您只需在图像标签中使用
self
:他们没有相同的父母&这就是为什么你会有这个问题
相关问题 更多 >
编程相关推荐