EasyGui ButtonBox不含按钮的图像

时间:2018-10-15 06:20:20

标签: python tkinter easygui

我正在使用easygui及其按钮箱来做一个非常小的GUI。 我的问题是:我的图像也显示为按钮,但不应该显示。在那儿 一种在按钮框中显示图像的方法,但是该图像不应“可单击”? 至 测试您必须做pip Install easygui

这是我的按钮箱呼叫:

import easygui
version = "Version 1.0 -- 10.2018"

main_options=["Doors EXPORT","ANALYSE","VISUALIZE","Auto-Mode","Configuration"]

choosed_option = gui.buttonbox(msg="",title = version, choices = main_options,image ="logo.gif" )

1 个答案:

答案 0 :(得分:1)

从我喜欢在easybox的按钮箱上找到的文档来看,没有什么东西表明该图像不应该是按钮或更改其状态的方式。但是,这是一个纯tkinter示例,应该接近您的需求。

import tkinter as tk


root = tk.Tk()
version = "Version 1.0 -- 10.2018"
root.title(version)
root.geometry("675x200")
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)

main_options=["Doors EXPORT","ANALYSE","VISUALIZE","Auto-Mode","Configuration"]

tk.Label(root, text="Here is where you message will go from the msg section of your buttonbox").grid(row=0, column=0, columnspan = len(main_options), stick="n", pady=(15,0))

img = tk.PhotoImage(file="logo.gif")
tk.Label(root,image=img).grid(row=1, column=0, pady=5)

frame2 = tk.Frame(root)
frame2.grid(row=2, column=0)

for ndex, item in enumerate(main_options):
    tk.Button(frame2, text=item).grid(row=0, column=ndex, ipadx=5, ipady=5, padx=5, pady=(30, 5), stick="ew")

root.mainloop()

您还可以创建一个类,该类基本上执行相同的操作,并像按钮框一样接受所有参数:

import tkinter as tk


options = ["Doors EXPORT","ANALYSE","VISUALIZE","Auto-Mode","Configuration"]
version = "Version 1.0 -- 10.2018"
msg = "Here is where you message will go from the msg section of your buttonbox"
ipath = "logo.gif"


class mock_buttonbox(tk.Tk):
    def __init__(self, var_msg = "", version = "", main_options = [], img_path=""):
        tk.Tk.__init__(self)
        self.title(version)
        self.geometry("675x200")
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)

        try:
            tk.Label(self, text=var_msg).grid(row=0, column=0, columnspan = len(main_options), stick="n", pady=(15,0))
            img = tk.PhotoImage(file=img_path)
            tk.Label(self,image=img).grid(row=1, column=0, pady=5)
        except:
            print("Bad image path, wrong image format or no options provided.")

        frame2 = tk.Frame(self)
        frame2.grid(row=2, column=0)

        try:
            for ndex, item in enumerate(main_options):
                tk.Button(frame2, text=item).grid(row=0, column=ndex, ipadx=5, ipady=5, padx=5, pady=(30, 5), stick="ew")
        except:
            print("No options provided or options are not a value argument for text field.")
        self.mainloop()

mock_buttonbox(var_msg = msg, version = version, main_options = options, img_path = ipath)