I'm wondering if there is any python code I can use to lock the size of my CMD window? I'm making a small text adventure game and want t at a specific size.
If it helps, I'm using windows 7, but wouldn't mind mac and linux compatible instructions. Thanks.
I don't think this is possible. If you want to control a gui directly, you should use a gui package like tkinter
for example
from Tkinter import *
window = Tk()
window.minsize(minw, minh)
window.maxsize(maxw, maxh)
add a text block to this and treat it just like a cmd window. You can read more about it on the Tkinter docs
you can use pyWinGUI for emulate text terminal with comctl.Edit control
Related
As far as I understand, it is not possible to modify the tkinter.colorchooser.askcolor as it uses the systems colorpicker dialog. Is this true?
from the source code: https://github.com/python/cpython/blob/3.9/Lib/tkinter/colorchooser.py
# this module provides an interface to the native color dialogue
# available in Tk 4.2 and newer.
The reason being is I wish to add an entry box to the dialog so that I would get the color code and user-entered text returned. Maybe it is possible to embed the dialog within a larger window? Is something like this possible, without using multiple windows?
I cannot find previous discussion anywhere else so I guess it is not a simple issue.
As far as I understand, it is not possible to modify the tkinter.colorchooser.askcolor as it uses the systems colorpicker dialog. Is this true?
Yes, that is true. At least on Windows and OSX. On Linux it's a custom dialog written in tcl/tk. You could start with that code and then make modifications to it, then write a tkinter wrapper around it. That wouldn't be particularly difficult if you know tcl/tk, but it's not exactly trivial either.
Maybe it is possible to embed the dialog within a larger window?
No, it's not.
I have made a gui using Tkinter and when i send that code to my friend to further work on, the places of buttons and other widgets get distorted.Is there a way by which i can assure that whatever OS he is using, it will show the same result as it shows on my system.
My friend is using mac and i'm working on windows.
I'm making an app using python. I want a very simple user interface just to read a query. It should contain a text box where to type the query and a submit button. Can I make such an interface without using any drag and drop softwares, i.e just by using the code?
Well simply you can't do that with pure python
BTW start with Tkinter as its more easy to learn than any other gui framework
Your expected code would look like in Tkinter:
import Tkinter as Tk
root = Tk.Tk()
def submit():
print "entered text were " + entry.get()
entry = Tk.Entry(root)
entry.pack()
button = Tk.Button(root,text='submit',command=submit)
button.pack()
root.mainloop()
By the way Tkinter is open source so feel free to look how the module is made
Well, there isn't really anything to say other than: no, you can't.
Unlike some other languages, Python cannot do too much without importing modules/libraries.
Meaning, to make a user-interface of any kind, you must first import a GUI development library such as Tkinter, wxPython, etc.
My python application launches a subprocess that creates a pyglet window. When the pyglet window opens, it is in front of all other windows, and takes keyboard focus. I'd like my pyglet window to open in the background, and not take focus. Is this possible?
Stripped-down version of the code I'm using:
import pyglet
pyglet.window.Window()
pyglet.app.run()
I'm using Windows 7, in case that makes a difference..
Reversing focus is OS specific:
pyglet does not provide OS specific window control. So most likely you will have to use an ad-hoc trick for quick&dirty solutions or try to approach it with extensions like pywin32 using Windows API and/or COM to list through the stack of taskbar applications to reverse stealing of focus. You can also try to create your own window (container - which you can manipulate) first - in order to delegate its context to pyglet.
Delaying stealing of focus
On the other hand if according to your program logic you just want to delay actual showing of you application you can play with visibility:
import pyglet
w = pyglet.window.Window()
w.set_visible(False)
pyglet.app.run()
So if you don't want to play with delegation of window context, you can probably do the following:
start your application w/o showing the window
find the focus of the current active window by getting its handle/id
show your window
give back the focus to the previous window
The above assumes working with windows API. I think MSDN had examples on focus changing.. If you know PID of your current window (main application) this should simplify the step 2.
I am thinking this might be more of a windows / window manager issue than your app - will something like this http://pcsupport.about.com/od/windowsxp/ht/stealingfocus02.htm help ??
Python 2.7 (32-bit) Windows: We're experimenting with Python 2.7's support for themed Tkinter (ttk) for simple GUI's and have come away very impressed!! The one area where the new theme support seems to have come up short is how OS specific common dialogs are wrapped.
Corrected: In other words, the MessageBox and ColorChooser common dialogs have "ugly" looking Win 95 style blocky looking buttons vs. the themed (rounded/gradient) buttons that normally show up on these common dialogs under XP, Vista, and Windows 7. (I'm testing on all 3 platforms with identical, un-themed results).
Note: The filedialog common dialogs (askopenfilename, askopenfilenames, asksaveasfilename, askdirectory) are all properly themed.
import tkMessageBox as messagebox
messagebox.showinfo()
import tkColorChooser as colorchooser
color = colorchooser.askcolor( parent=root, title='Customize colors' )
Any ideas on what's required to get Tkinter's MessageBox and ColorChooser common dialogs to be OS theme compatible (at least under Windows XP or higher)?
Your observation is mainly correct. I do see what you are referring to in the messagebox and the colorchooser. However, my filedialogs all seem to have properly rounded buttons, etc.
My recommendation for you on making the messagebox is to create your own messagebox using the TopLevel widget, and then define what you need on it and the appropriate behavior for the different buttons (it's definitely a bit harder than just using a messagebox, but if you really need the new style buttons, it'll work).
I don't think you can hack together a solution for the colorchooser problem, however.
I though for a minute that perhaps Python 3.1 had fixed this problem, but sadly, I tried and that isn't the case. I suppose if you need the user to pick a color, the buttons will have to be ugly.
An option to get better looking dialog boxes is to compile your script to an executable using pyinstaller. I explain this more thouroughly here.
tl;dr, it appears that compiling with pyinstaller allows you to have dialog boxes with the style of the currently running OS, but not custom styles.