How to make a window with buttons in python

后端 未结 6 1115
挽巷
挽巷 2021-02-04 16:50

How do I create a function that makes a window with two buttons, where each button has a specified string and, if clicked on, returns a specified variable? Similar to @ 3:05 in

6条回答
  •  温柔的废话
    2021-02-04 17:22

    You should take a look at wxpython, a GUI library that is quite easy to start with if you have some python knowledge.

    The following code will create a window for you (source):

    import wx
    
    app = wx.App(False)  # Create a new app, don't redirect stdout/stderr to a window.
    frame = wx.Frame(None, wx.ID_ANY, "Hello World") # A Frame is a top-level window.
    frame.Show(True)     # Show the frame.
    app.MainLoop()
    

    Take a look at this section (how to create buttons). But start with the installation instructions.

提交回复
热议问题