,点击确定按钮后,能够将输入的信息显示在gui中。 3、设置一个显示框,用来显示程序运行过程中的信息。 4、设置一个退出按钮,点击后能够退出程序。

以下是示例代码:

import tkinter as tk

class GUI(tk.Tk):
    def __init__(self):
        super().__init__()

        # 设置窗口标题
        self.title("GUI")

        # 设置窗口大小
        self.geometry("500x300")

        # 设置下拉框
        self.time_options = ["10:00", "12:00", "14:00", "16:00", "18:00"]
        self.time_var = tk.StringVar(self)
        self.time_var.set(self.time_options[0])
        self.time_dropdown = tk.OptionMenu(self, self.time_var, *self.time_options)
        self.time_dropdown.pack()

        self.event_options = ["事件1", "事件2", "事件3", "事件4", "事件5"]
        self.event_var = tk.StringVar(self)
        self.event_var.set(self.event_options[0])
        self.event_dropdown = tk.OptionMenu(self, self.event_var, *self.event_options)
        self.event_dropdown.pack()

        # 设置输入框和确定按钮
        self.input_label = tk.Label(self, text="请输入信息:")
        self.input_label.pack()

        self.input_entry = tk.Entry(self)
        self.input_entry.pack()

        self.submit_button = tk.Button(self, text="确定", command=self.show_info)
        self.submit_button.pack()

        # 设置显示框
        self.info_label = tk.Label(self, text="")
        self.info_label.pack()

        # 设置退出按钮
        self.quit_button = tk.Button(self, text="退出", command=self.quit)
        self.quit_button.pack()

    def show_info(self):
        info = self.input_entry.get()
        time = self.time_var.get()
        event = self.event_var.get()
        self.info_label.config(text=f"时间:{time},事件:{event},信息:{info}")

if __name__ == "__main__":
    gui = GUI()
    gui.mainloop()

运行该程序后,会出现一个gui窗口,其中包含了一个时间下拉框、一个事件下拉框、一个输入框、一个确定按钮、一个显示框和一个退出按钮。用户可以选择时间和事件,然后在输入框中输入信息,点击确定按钮后,程序会将用户输入的信息显示在显示框中。用户也可以点击退出按钮来退出程序

使用tkinter模块制作一个gui需要实现以下功能:1、设置两个下拉框。一个下拉框能够实现时间点选一个下来框用来绑定其他事件。2、设置一个窗口功能用来输入信息并且设置确定按钮

原文地址: https://www.cveoy.top/t/topic/eCSz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录