Python Forum
Best Method for simple GUI? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Best Method for simple GUI? (/thread-6291.html)



Best Method for simple GUI? - PythonAndArduino - Nov-14-2017

I've made a number guessing game, and I want to build a GUI so it can be played outside of a command prompt window so that I can eventually export it as an .exe that I can share.

What is the best module and/or method to use? PyGame seems absurdly complicated for me just wanting to display text and simple typed inputs so I haven't tried that yet. Tkinter seems to want to always close a window and open a new one rather than just update a single, consistent existing window. Is there another way that I can create a single window to display a single changeable line of text and a small input window for typed inputs that are max 3 characters long?


RE: Best Method for simple GUI? - metulburr - Nov-14-2017

You can create in tkinter a text that can change. You can use a StringVar and set that as a label's or other text of widget and change it on the fly
http://effbot.org/tkinterbook/label.htm


pygame doesnt come with a UI toolkit, so yeah it would make it more complicated than what you are looking for. Unless your end result is gaming, then i would learn it and use it.


RE: Best Method for simple GUI? - PythonAndArduino - Nov-14-2017

That... is brilliant. Thank you.


RE: Best Method for simple GUI? - zykbee - Nov-17-2017

Have you considered using tkinter to set up an entry box, and having the entry display in a text box upon click of a button ? For example:
   
    def __init__(self, master):
        Frame.__init__(self, master)
        self.grid()
        self.create_widgets()
    def create_widgets(self):
        self.text = Text(self, width = 35, height =5, wrap = WORD)###this is where you'd put entry.
        self.text.grid(row =1, column=1, sticky = W)

        self.submit_button = Button(self, text = "Submit", command = self.reveal)###this is the button you'd hit to perform your function
        self.submit_button.grid(row = 2, column = 0, sticky =W)

        self.text1 = Text(self, width = 35, height =5, wrap = WORD) ###this places a second text box in grid.
        self.text1.grid(row = 3, column =0, columnspan = 2, sticky=W)
    def reveal(self): # this reveals w/e you wrote in first textbox, or you can configure to reveal whatever you want 
        content = self.text.get("1.0","end-1c") 
        self.text1.insert(3.0, content)
I'm new to the game myself, but hopefully this can provide you a glint of guidance :-D


RE: Best Method for simple GUI? - heiner55 - Nov-17-2017

See https://python-forum.io/Thread-Tkinter-Need-some-basic-help-with-GUI-graphics