askstring Window to the top under Windows

Jussi Salmela tiedon_jano at hotmail.com
Tue Mar 6 12:31:31 EST 2007


iwl kirjoitti:
> On 6 Mrz., 14:48, "Tim Golden" <tjgol... at gmail.com> wrote:
>> On Mar 6, 1:13 pm, "iwl" <Ingo.W... at gmx.de> wrote:
>>
>> It's not clear whether you're talking about the usual
>> "Why do I get a DOS window when I run my python script?"
>> question -- to which the answer is, in essence, change
>> your script's extension to .pyw or use the pythonw.exe
>> executable -- or "Why _when I use askstring_ do I get
>> an empty window?". If it's the latter, then I don't
>> know, but can you provide a small example script which
>> exhibits the behaviour.
>>
>> TJG
> 
>>>> import tkSimpleDialog
>>>> tkSimpleDialog.askstring("a","b")
> 
> at the python Console under XP (not pythonw).
> 
> -> instead of only showing the Inputwindow at the top,
> some additional empty window is shown, both not on top.
> 

I assumed that by "python Console" you mean the IDLE editor/interpreter.
I entered your 2 lines and the behaviour is the same on Win XP. I doubt 
it has nothing to do with the OS, though.

(A word of warning but don't tell anyone: I've never used Tkinter, I use 
wxPython!)

Every GUI implementation has a command loop and things to initiate the 
correct execution environment. I think that's what you are missing here 
and that's causing the odd behaviour.

I found an example (16.1.2.2 A Simple Hello World Program) in Python 2.4 
and modified as shown:

#===============================================
from Tkinter import *
import tkSimpleDialog # <<<=== modification here

class Application(Frame):
     def say_hi(self):
         print "hi there, everyone!"

     def createWidgets(self):
         self.QUIT = Button(self)
         self.QUIT["text"] = "QUIT"
         self.QUIT["fg"]   = "red"
         self.QUIT["command"] =  self.quit

         self.QUIT.pack({"side": "left"})

         self.hi_there = Button(self)
         self.hi_there["text"] = "Hello",
         self.hi_there["command"] = self.say_hi

         self.hi_there.pack({"side": "left"})

     def __init__(self, master=None):
         Frame.__init__(self, master)
         self.pack()
         self.createWidgets()

root = Tk()
app = Application(master=root)
app.mainloop()
tkSimpleDialog.askstring("a","b") # <<<=== modification here
root.destroy()
#===============================================

If you run it, it first shows the "Hello dialog" and after clicking the 
QUIT button, your askstring gets run.

So: nothing wrong with Python, Tkinter or tkSimpleDialog.askstring.
Just carry on having fun with Python!

HTH,
Jussi



More information about the Python-list mailing list