I want to know which version of Tkintr my Python 2.7 is running...
Thanks for the support :)
I have already done:
import Tkinter
Tkinter.TclVersion
but it is not working
The module variable TkVersion will return a floating point number representing the version of the underlying tk library.
For example:
import tkinter as tk
the_version = tk.TkVersion
Related
In my application, the user needs to browse for files. However, the askdirectory from tkFileDialog isn't really comfortable for using and browsing files since it's somewhat outdated.
It looks like this:
What I want to achieve should look like the "default" windows browse dialog. Like this:
(Source https://www.pythontutorial.net/tkinter/tkinter-open-file-dialog/)
I am not sure (since I couldn't find proof) but I remember someone telling me that it looks like this because I am using Python 2.7 and not 3+.
Is that true? Does an alternative exist?
It seems it has something to do with your version, as I have done a bit of research and I am using python 3 with the included tkinter and it shows a normal windows explorer popup. So, if you are using one of the up-to-date versions, it should be the OS' default. (I am unable to test that as python 2 will not work properly on my machine although I can confirm since you are using an older one)
I recreated your case with this code:
from tkinter import *
root = Tk()
filedialog.askdirectory()
root.mainloop()
You can try using askopenfilename(). It displays the standard Open File dialog box.
For example:
from tkinter import *
from tkinter import filedialog as fd
root = Tk()
root.title("Button to open files")
root.geometry("500x500")
def openfd(*args):
askk = askopenfilename()
btn = Button(root, text="Click to open file", command=openfd)
btn.place(x=200, y=200)
root.mainloop()
You can read more about it at https://www.pythontutorial.net/tkinter/tkinter-open-file-dialog/.
I simply copied and pasted these code from rdkit (https://www.rdkit.org/docs/GettingStartedInPython.html#generating-images-of-fingerprint-bits)
I was expecting to generate graphs.
However, I got a long string.
from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem import Draw
mol = Chem.MolFromSmiles('c1ccccc1CC1CC1')
bi = {}
fp = AllChem.GetMorganFingerprintAsBitVect(mol, radius=2, bitInfo=bi)
mfp2_svg = Draw.DrawMorganBit(mol, 872, bi)
rdkbi = {}
rdkfp = Chem.RDKFingerprint(mol, maxPath=5, bitInfo=rdkbi)
rdk_svg = Draw.DrawRDKitBit(mol, 1553, rdkbi)
Does anyone know how to solve this problem?
Thanks a lot in advanced.
I am now using python 3.6 and latest rdkit version (2018.09.1.0) on Windows
To see depiction in IPython or Jupyter notebooks just add
from rdkit.Chem.Draw import IPythonConsole
The RDKit 'GettingStarted' did not use Ipython for the sample scripts, so the import of the IPythonConsole is never declared, allthough it is not new.
Look in the RDKit Blog or search for notebooks the web and you see it is a standard.
I have some issues in maxplus, the python distribution in 3ds max with pyside.
I try to parent my qtmainwindow to the max window. To minimize my qtmainwindow when max is minimized.
We want to leave the maxplus python installation untouched so I cannot install sip or shiboken to use wrapinstance to get a qobject. Now I would like to know how the parenting would be possible without those packages.
edit:
I recognized that shiboken is available but when I try to parent my QMainWindow to the applicatin it gives a
** system exception **
here is a bit of code i hope that helps to understand:
from PySide import QtCore, QtGui,shiboken
import MaxPlus
class ControlMainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(ControlMainWindow, self).__init__(parent)
maxWinHwd = MaxPlus.Core.GetWindowHandle()
parent=shiboken.wrapInstance(long(maxWinHwd), QtGui.QWidget)
self.setParent(parent)
def main():
global app
app = QtGui.QApplication.instance()
if not app:
app = QtGui.QApplication(sys.argv)
global window
window=ControlMainWindow()
window.show()
if __name__ == '__main__':
main()
Thanks in advance
I'm tackling the exact same problem now, so this is the best solution I've found so far that works OOTB without having to resort to relying on the Blur 3ds max Python extensions:
http://tech-artists.org/forum/showthread.php?5162-MaxPlus-parent-PySide-Window-to-Max-Window
I've tried to make a commented version of the code here as well, though I'm new to ctypes, so it may not be 100% correct:
http://pastebin.com/Sed2g89N
I hope that helps!
I have a small project that uses matplotlib to display a wafer map of die. I am "compiling" the single-file Python (2.7) into an executable using PyInstaller with the --onefile option, so that non-Python users at the company can execute it in Windows.
The executable takes quite a while to load, up to 15s. As a workaround, I removed all the wafer-map plotting capabilities of the program and built a "Lite" version. This Lite version runs in <1s, as it should. In addition, the Lite version's .exe is 85% smaller (as expected).
So it looks like the Matplotlib stuff is bloating the exe and is making it take a long time to load.
Here's my thought process:
I should be able to get the file size down and decrease the load time if I only import the modules I use rather than all of matplotlib.pyplot. I assume that the import matplotlib.pyplot as pyplot line is importing a whole bunch of extra stuff that I'm not using, such as scatterplots.
Here's my question:
How can I only import the parts of matplotlib that I use?
Here's my (relevant) code, with a lot of the fluff (like line colors) removed. Also, please ignore the lack of PEP8 conformity - this was written before I decided to follow it :-)
from __future__ import print_function
import math
import matplotlib.pyplot as pyplot
import matplotlib.patches
fig = pyplot.figure(1)
ax = fig.add_subplot(111, aspect='equal')
ax.axis([xAxisMin, xAxisMax, yAxisMin, yAxisMax])
die = matplotlib.patches.Rectangle(coords, dieX, dieY)
ax.add_patch(die)
arc = matplotlib.patches.Arc((0, 0),
width=exclDia, height=exclDia, angle=-90,
theta1=ang, theta2=-ang)
flat = matplotlib.lines.Line2D([-flatX, flatX],
[flatY, flatY])
# Extra code that actually adds everything to the figure
fig.show()
So it looks like I'm using only:
matplotlib.pyplot.figure
matplotlib.patches.Rectangle
matplotlib.patches.Arc
matplotlib.lines.Line2D
However, those above are not individual modules in matplotlib (to my knowledge) - they are classes of their parent module (patches, lines, pyplot), so I can't just `import matplotlib.patches.Arc' or anything.
So. What's my next step?
I need to accept info from the user in python's turtle. however the turtle.textinput function only works in versions 3.x and upwards is there an alternative I can use in version 2.X ?
This is what textinput actually does:
import tkSimpleDialog
tkSimpleDialog.askstring('title', 'prompt')
It requires you to have a turtle screen open, of course.