0

so, I have a small program which I run using tkinter. when the user start the program he is asked in the command line to enter a user name. my problem is that after he enters the name, the program starts but it is behind the command window (or pycharm if I use it). I saw that if I don't use the command line to enter the user name, the window pops up when I call root.mainloop() but I have to use the command line becuase if the user name is illegal I want the user to enter a new one.

I tried everyt I looked here how-to-give-tkinter-file-focuse but everything there didn't work as well.

thanks for the help!

Community
  • 1
  • 1
Dvir Itzko
  • 404
  • 4
  • 17
  • 2
    Why do you have the user enter a username on a command line for a GUI program? Why not use a dialog window? – Bryan Oakley Jan 15 '16 at 16:15
  • actually I didn't think about doing something like this. But the problem is that I don't know how to get input from user in a dialog window.. and also, I need to make sure the user name is legal (dosn't contains any special chars or none English chars) how can I do this if I use dialog window? – Dvir Itzko Jan 15 '16 at 17:49
  • see http://stackoverflow.com/questions/10057672/correct-way-to-implement-a-custom-popup-tkinter-dialog-box – Bryan Oakley Jan 15 '16 at 18:00

1 Answers1

0

You can set focus to your window, so if your window is called root:

root.focus_set()

Just call that whenever you want the focus to change to the tk window.

T Bell
  • 96
  • 4
  • I have tried this already. when I use focus_set it just make the new window blink in the taskbar. but it still don't really show it. – Dvir Itzko Jan 16 '16 at 07:23