Everything related to SDK.
User avatar
By Brany
#395212
I've just managed to use tkinter from within pymaxwell.exe, you can try something like this:
Code: Select all
from Tkinter import *
import sys
if not hasattr(sys, 'argv'):
    sys.argv = [sys.executable]
root = Tk()
w = Label(root, text="Hello, world!")
w.pack()
root.mainloop()
User avatar
By seghier
#395213
thanks alot Brany
it work fine and also work with this :
Code: Select all
from Tkinter import *
sys.argv = [sys.executable]
root = Tk()
w = Label(root, text="Hello, world!")
w.pack()
root.mainloop()
is it important to add this two lines? :
import sys
if not hasattr(sys, 'argv'):
------------
this code to create button is it possible to use a button to load mxs file and use another button to make a change in the scene ?
Code: Select all
from Tkinter import *

sys.argv = [sys.executable]

root = Tk()
topFrame = Frame(root)
topFrame.pack()
bottomFrame = Frame(root)
bottomFrame.pack(side=BOTTOM)

button1 = Button(topFrame, text='Button 1', fg='red')
button2 = Button(bottomFrame, text='Button 2', fg='blue')

button1.pack(side=LEFT)
button2.pack(side=BOTTOM)

root.mainloop()
User avatar
By seghier
#395214
there are some examples about ttk in maxwell>python>tcl>tk8.5>ttk folder
this example didn't work in pymaxwell even i add the new line : sys.argv = [sys.executable]
Code: Select all
from tkinter import *
from tkinter import ttk

def calculate(*args):
    try:
        value = float(feet.get())
        meters.set((0.3048 * value * 10000.0 + 0.5)/10000.0)
    except ValueError:
        pass
    
root = Tk()
root.title("Feet to Meters")

mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)

feet = StringVar()
meters = StringVar()

feet_entry = ttk.Entry(mainframe, width=7, textvariable=feet)
feet_entry.grid(column=2, row=1, sticky=(W, E))

ttk.Label(mainframe, textvariable=meters).grid(column=2, row=2, sticky=(W, E))
ttk.Button(mainframe, text="Calculate", command=calculate).grid(column=3, row=3, sticky=W)

ttk.Label(mainframe, text="feet").grid(column=3, row=1, sticky=W)
ttk.Label(mainframe, text="is equivalent to").grid(column=1, row=2, sticky=E)
ttk.Label(mainframe, text="meters").grid(column=3, row=2, sticky=W)

for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)

feet_entry.focus()
root.bind('<Return>', calculate)

root.mainloop()
User avatar
By Brany
#395216
is it important to add this two lines? :
import sys
if not hasattr(sys, 'argv'):
import sys -> mandatory if you run your script from ouside pymaxwell.exe (let's say the usual python interpreter installed in the system)
if not hasattr(sys, 'argv'): -> 'argv' does not exists running the script from pymaxwell.exe, but if you run it from a regular python interpreter it will exist, and it can have parameters that you don't want to lose, so you only have to set this in the case it doesnt exist.

In a nutshell, I made this sample script in a way that it can be run in pymaxwell.exe and in any python interpreter installed in the system.
this code to create button is it possible to use a button to load mxs file and use another button to make a change in the scene ?
I have never used Tk before, but you can do that for sure. I've used Qt for python to do such as things.
User avatar
By seghier
#395218
thanks for explanation
this also work in pymaxwell and other python editor ( i tried with cmd and pyCharm )
Code: Select all
from Tkinter import *
sys.argv = [sys.executable]
root = Tk()
w = Label(root, text="Hello, world!")
w.pack()
root.mainloop()
i will try Qt
what i want create from exist script in maxwell folder is to use button to load scene for example and apply a command and run without need to write in pymaxwell
User avatar
By Brany
#395223
I'm not sure if you are talking about pyqt_edit_physical_sky.py in %MAXWELL4_ROOT%/scripts/python/, but this is a good starting point if you finally use Qt.

Take into account that pymaxwell doesn't include the PyQt module, so you have to install it in the python interpreter.
User avatar
By seghier
#395228
i copy pymaxwell to C:\Python27\lib\site-packages\ and this is the error

Traceback (most recent call last):
File "C:/Users/archi/Desktop/sun2.py", line 7, in <module>
from pymaxwell import *
File "C:\Python27\lib\site-packages\pymaxwell\__init__.py", line 13, in <module>
from new import instancemethod as new_instancemethod
ImportError: cannot import name instancemethod

i also installed pyqt4 with python 3.5 ; but there is difference between pyqt4 and pyqt5
User avatar
By Brany
#395229
you have to use
Code: Select all
from pymaxwell4 import *
You must use "pymaxwell" module instead of "pymaxwell4" from within pymaxwell.exe due a bug, sorry about the inconvenience! It will be fixed for the next release.
User avatar
By seghier
#395230
yes i used : from pymaxwell import*
it work fine using pycharm and i read in the script

# Script must run in a python console, not from within pymaxwell
why pymaxwell can't run the script ?
-------
and i hope see tutorial about using qt designer + pymaxwell and also an update of this script with pyqt5
User avatar
By Brany
#395239
How did you imported pymaxwell4?

There are two ways:
Code: Select all
from pymaxwell4 import *
mxs = Cmaxwell(mwcallback)
mxs.readMXS('C:/scene.mxs')
Code: Select all
import pymaxwell4 as mw
mxs = mw.Cmaxwell(mw.mwcallback)
mxs.readMXS('C:/scene.mxs')
Hope it helps

Probably the use of two "." in the file […]

Maxwell and Blender

An addon for Blender would be amazing. It would in[…]

Hey Patrik, thanks for the suggestion. 🙌🏼 Creams […]

Hi ki_cz, this is my attempt with another engine,[…]