from tkinter import *from tkinter import simpledialogimport sys, osclass SettingDialog(simpledialog.Dialog):def body(self, master):Label(master, text="First").grid(row=0, sticky=W)root = Tk()#Without "default" keyword, only root (parent) window icon is changed#other child dialogs still use Tk iconroot.iconbitmap(default='AC.ico')#call withdraw() to remove parent window, only show the child dialog.root.withdraw()SettingDialog(root, "hello")
Thursday, August 26, 2010
Create a simple dialog in Tkinter (python)
To create a dialog in Python using Tkinter module, just inherit from simpledialog.Dialog class from tkinter.simpledialog module (Python 3).
Wednesday, August 25, 2010
cx_Freeze and Python executable
To make the executable created by cx_Freeze on Python code works on other computers, you have to copy the following files to the executable directory:
- C:\WINDOWS\WinSxS\Manifests\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022. 8_x-ww_d08d0375.manifest
- C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022 .8_x-ww_d08d0375\
msvcm90.dll
msvcp90.dll
msvcr90.dll
You can download these files from Microsoft Visual C++ 2008 Redistributable Package (x86) (11/29/2007)
Friday, August 20, 2010
Create Single Instance Python Application in Windows
Source by Dragan Jovelic.
from win32event import CreateMutexfrom win32api import CloseHandle, GetLastErrorfrom winerror import ERROR_ALREADY_EXISTSclass singleinstance:""" Limits application to single instance """def __init__(self):self.mutexname = "testmutex_{D0E858DF-985E-4907-B7FB-8D732C3FC3B9}"self.mutex = CreateMutex(None, False, self.mutexname)self.lasterror = GetLastError()def aleradyrunning(self):return (self.lasterror == ERROR_ALREADY_EXISTS)def __del__(self):if self.mutex:CloseHandle(self.mutex)#---------------------------------------------## sample usage:#from singleinstance import singleinstancefrom sys import exit# do this at beginnig of your applicationmyapp = singleinstance()# check is another instance of same program runningif myapp.aleradyrunning():print "Another instance of this program is already running"exit(0)# not running, safe to continue...print "No another instance is running, can continue here"
Subscribe to:
Posts (Atom)