jeejz / pythonProjects

1 stars 0 forks source link

Nice boxes! #1

Open MikeTheWatchGuy opened 5 years ago

MikeTheWatchGuy commented 5 years ago

You're the first person I know of that's used the Vertical Separator Element. And you used it in a great way. I suppose you could have done it with a Text Element that has | as the value. I just tried that and your solution is superior.

I couldn't figure out what you were doing by looking at the code. For 20 lines of code, it sure does a lot.

I hope PySimpleGUI has been of great help to your project.

For the fun of it, I ran your code using PySimpleGUIQt.

I needed to change:

Here's that code:

import PySimpleGUIQt as psg

def DrawBox():
    column = [[]]
    input1 = []
    for i in range(1,10):
        for j in range(1,10):
            key = str(i)+str(j)
            input1.append(psg.InputText(default_text=key,do_not_clear=True, size=(3, 1), key=(key)))
            if j%3 == 0 :
                input1.append(psg.Txt('|'))
        column.append(input1)
        input1 = []
        if i%3 == 0:
            column.append([psg.Text('_' * 50,justification='CENTER')])

    layout = [  [psg.Column(column, size=(800,800))],
              [psg.OK(), psg.Cancel() ]]

    window =  psg.Window('Submit Question',auto_size_text=True ).Layout(layout)

    while True:
        event, value = window.Read()
        print(event, value)
        if event is None or event == 'Exit' or event == 'Cancel':
            break

DrawBox()

And here's what it looks like using my latest release (it may not be available yet on PyPI)

snag-0255

Can wait to see more of your stuff in the future. Nice work.

MikeTheWatchGuy commented 5 years ago

Oh, one more thing... you should add a justification parm to your input text elements. They are left justified by default. I think you want right.

Here it is right justified.

snag-0258

jeejz commented 5 years ago

Oh, one more thing... you should add a justification parm to your input text elements. They are left justified by default. I think you want right.

Here it is right justified.

snag-0258

Hi @MikeTheWatchGuy

Thanks for your suggestion.

I was trying to create a Sudoku Solver application. And I added this splitter for getting a proper splitter of 9 3X3 matrices. Here as you observer, the split is improper (even i tried using the txt field, as you suggested), can you suggest me something to aesthetically design the ui with a uniformly lined grid.

Also, i do have question on name of the input text field. Can we use integers as the key of the fields. When i have tried, the numbers till 26 are always returning as None and the changes in the ui are not reflected back properly. Can you please advice.

Many Thanks for you kind support.

MikeTheWatchGuy commented 5 years ago

Yes, there is a way to get lines and a table built completely with graphics. Take a look at this crossword demo program. https://github.com/MikeTheWatchGuy/PySimpleGUI/blob/master/DemoPrograms/Demo_Crossword_Puzzle.py

It takes a bit more work as you have to detect when a square is clicked on, then you'll have to intercept the keyboard input and do your own editing (detecting backspace). The result will likely be worth the effort if the look is super important.

I think it looks pretty good overall. I would add the bars to the left hand side so that it mirrors the right side.

You can also wait a bit for me to finish the Qt version where I may be able to see a "proper" vertical separator. No guarantees though.

If I can make a crossword puzzle that inserts letters when clicked, then I think you should be able to make this game using similar techniques.

snag-0185

MikeTheWatchGuy commented 5 years ago

About keys... you can use anything as a key, including a tuple of integers. If you want to use a (row, col) tuple for a key it will work.

I'll check to make sure it works properly. If you can open an Issue when you have problems like this, that would be helpful.

MikeTheWatchGuy commented 5 years ago

Here is a sample program showing using integers as keys. You can see that the event value coming back is an int. Each square has the key value shown as the default. When modify any square, an event is immediately returned with the key value (an int).

import sys

if sys.version_info[0] >= 3:
    import PySimpleGUI as sg
else:
    import PySimpleGUI27 as sg

layout = []
for i in range(10):
    row = []
    for j in range(20):
        row.append (sg.Input('{}'.format(i*20+j), key=i*20+j, change_submits=True, size=(3,1), do_not_clear=True))
    layout.append(row)

window = sg.Window('Window Title').Layout(layout)

while True:             # Event Loop
    event, values = window.Read()
    print(event, type(event))
    if event is None or event == 'Exit':
        break

window.Close()