How do I make a 800x800 console window with python - python

I've recently been making a simple text based game in python 3.9 and I want to make it so when you run the .exe it will open a console window that is 800x800 or whatever ratio I want to put in. Could anyone help me do this please!

The only option that i can think of its to run tour program in PowerShell, this one can resize it self with something like this
$pshost = get-host
$pswindow = $pshost.ui.rawui
$newsize = $pswindow.buffersize
$newsize.height = 3000
$newsize.width = 150
$pswindow.buffersize = $newsize
$newsize = $pswindow.windowsize
$newsize.height = 50
$newsize.width = 150
$pswindow.windowsize = $newsize
I get this code from here
You can call this commands inside python with OS module.
I couldnt test the code cause #teamLinux.

Related

Displaying CadQuery data in a QT5 window in Python

I wrote a python program using the PyQt5 libraries. This program I can make into an executable with pyinstaller.
I would like to add the functionality to show a 3D cad image based on user inputs. The CadQuery package has a nice intuitive approach and I would like to use it.
From the OCC.Display.qtDisplay I take my viewer. The problem is that the viewer does not accept the workplanes generated by CadQuery. I prefer not to export to files, but directly port the results from the cad generator to the viewer. Does anyone have any suggestions or experiences?
The following (partial) code works to display an AIS shape:
import OCC.Display.qtDisplay as qtDisplay
import cadquery as cq
self.canvas = qtDisplay.qtViewer3d(self)
self.horizontalLayout.addWidget(self.canvas)
a_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape()
self.ais_box = self.canvas._display.DisplayShape(a_box)[0]
self.canvas._display.FitAll()
but adding the following code (including the example bottle) does not:
self.makebottle()
self.canvas._display.DisplayShape(self.result.solids())
self.canvas._display.FitAll()
def makebottle(self):
(L,w,t) = (20.0, 6.0, 3.0)
s = cq.Workplane("XY")
# Draw half the profile of the bottle and extrude it
p = (s.center(-L/2.0, 0).vLine(w/2.0)
.threePointArc((L/2.0, w/2.0 + t),(L, w/2.0)).vLine(-w/2.0)
.mirrorX().extrude(30.0,True))
#make the neck
p = p.faces(">Z").workplane(centerOption="CenterOfMass").circle(3.0).extrude(2.0,True)
#make a shell
self.result = p.faces(">Z").shell(0.3)
Should I try to convert the workplanes? or use another package to make this work.

(Python - Tkinter) During a function, using an image as second window background

So I've looked around at forums and video tutorials but I can't seem to solve the problem I'm having. Basically, I'm creating a GUI with multiple windows. When trying to set up my second window, I attempt to set an image as the background using the following code;
def openMusicPage(): 1
MusicPage = Tk() 2
MusicPage.title('Now This Is Epic: Top Music Chart') 3
MusicPage.configure(width = 800, height = 505) 4
# Background`enter code here`
MusicBackground = PhotoImage(file="MusicBackground.gif") 5
MusicBackground_label = Label(MusicPage, image = MusicBackground) 6
MusicBackground_label.image=MusicBackground 7
MusicBackground_label.place(x=0, y=0) 8
The error occurs on the 6th line saying the image doesn't exist. On other forums and videos, I've seen suggestions to add the 7th line to fix this issue by referencing the image again. However, this hasn't helped and I continue to receive the error. Any suggestions as to how I could solve this issue? Noting, I am only able to use Tkinter for this assignment.
Thanks in advance!
Only use one instance of Tk(). For additional windows use Toplevel(). Change that and it works just fine.

Python Tkinter Label Refresh Woes

Im back again with another python issue.
A short while ago I wrote a console based program that pulls stats from a bitcoin miner on your local network. I've decided I'd like to turn it into a gui, and choose a combination of EasyGUI and Tkinter for my program.
My input boxes (ip, refresh rate,asic type) are all using EasyGUI, simply to save lines of code as Tkinter would take far more writing to accomplish the same. However, My actual results page is written using Tkinter as it allows me to refresh the displayed data at a user-defined interval.
My issue is this:
I had my program running happily, and then made some small ui tweaks (title, font, etc) and now after my most recent compile (using pyinstaller) I've noticed the stats (labels) don't update at all. I have looked over my code countless times now and cannot seem to find what is blocking the stats from changing at the defined intervals.
I am hoping someone with a fresh pair of eyes can help me find my stupid mistake, as it was running perfectly before these small additions.
Heres a cut-down version that still runs and produces the same issue:
import Tkinter as tk
from pycgminer import CgminerAPI
cgminer = CgminerAPI()
cgminer.host = 192.168.x.x
summary = cgminer.summary()
update = 1000
def L1(label):
def hashrate():
msg = "Your current GH/S = "
speed = msg , summary['SUMMARY'][0]['GHS 5s']
label.config(text=speed)
label.after(update, hashrate)
hashrate()
root = tk.Tk()
root.title("Eyes On Miner GUI V0.2")
label = tk.Label(root)
label.pack()
L1(label)
root.mainloop()
Full code on pastebin, in case you'd like to try to run it yourself. (python 2.7) Full Code
I ran this much of your code, substituting time() for the summary. It works in IDLE. From the console, either run with python -i program.py or add root.mainloop.
import tkinter as tk
from time import time
update = 1000
def L1(label):
def hashrate():
msg = "Your current GH/S = "
speed = msg , time()
label.config(text=speed)
label.after(update, hashrate)
hashrate()
root = tk.Tk()
root.title("Eyes On Miner GUI V0.2")
label = tk.Label(root)
label.pack()
L1(label)
If the problem is not with summary['SUMMARY'][0]['GHS 5s'], then there must be an incompatibility with either CgminerAPI or more likely with easygui. The latter is meant to replace tkinter, not be used together with it. If the code worked at first and then quit, then one of the additional functions you used must have triggered a conflict.

python auto clears everything on screen after 298 lines

my problem is that python.exe auto clears everything ive printed to it, after a certain amount of lines has been reached, for example i created the following program
a = 0
for a in range(0, 10000):
print(str(a) + ':> cola')
delay = input('BLARG :>')
now when i ran this in python .exe, i got the following result.
IMAGE1, and it carried on like this till it reached the end. IMAGE2 now the problem is python erased everything in the first image that came before the 9701st print which is a tad troublesome, does anyone have any advice on how to prevent python auto clearing everything.
This is not a python problem. change settings of your console ~v1k45
Windows' CMD you're using have a limit of old output it remembers.
I don't have Windows in English, so I do translation of names of the options myself, and they can differ from reality.
To change the limit, right-click on it's title bar and select Properties (for current window, or Defaults to change it for all future cmd windows), go to the tab Layout and increase heigth of Buffer size:

graphics.py GraphWin automatically closing

I'm new to Python and trying to learn graphics with John Zelle's graphics.py. I'm writing the Python scripts in MacVim and executing from the terminal (Mac OS 10.9.2) on Python 3. If I try to open a new window with GraphWin() the window opens briefly but then immediately closes.
Ex:
from graphics import *
win = GraphWin("circle",500,500)
c = Circle(point(100,100),30)
c.draw(win)
GUI elements with TkInter work just fine.
Any ideas why this might be happening?
Thanks!
If the statements you've shown in your question were entered as a script, and you just ran the script, then the problem is that the window is closed implicitly when the script ends. You will see in the very first example from the documentation (which also appears in the source code for graphics.py itself):
from graphics import *
def main():
win = GraphWin("My Circle", 100, 100)
c = Circle(Point(50,50), 10)
c.draw(win)
win.getMouse() # Pause to view result
win.close()
main()
Notice that the author has specifically included a statement to pause before closing the window.
If, instead of a script, you just type the statements in one by one at an interactive Python prompt, then as long as that Python prompt is open, the graphics window stays open (until you explicitly close it, or close the Python session).

Categories

Resources