Apply GTK theme for Python window Ubuntu 14.04 - python

I am rather new to Python and I don't seem to find any solution of changing the GTK theme that functions on my system. I run Ubuntu 14.04 with Python 2.7.6. The following is a simplified version of the code I'm currently working on:
import gtk
import webkit
gtk.rc_parse('/home/viktor/.themes/Elegant Brit/gtk-2.0/gtkrc')
view = webkit.WebView()
sw = gtk.ScrolledWindow()
sw.add(view)
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.add(sw)
win.show_all()
view.open("http://w3.org/")
gtk.main()
I can't seem to find anything that works for me. Any help is appreciated.

the theme can be modified using gtkrc files stored in the following path:
/usr/share/themes/[YOUR THEME]/[GTK VERSION]/gtkrc
use the following code to set the theme manually in your program
import os
os.environ['GTK2_RC_FILES'] = '/PATH/TO/THEME/gtkrc'
and walla! Your window will now use the specified theme.
Tested this using wxPython 2.8.

Related

Tkinter full screen not working in Python 3.10 for Mac OS

I just upgraded Python from 3.8 to 3.10 and the Tkinter full screen attribute no longer works as it used to.
I'm using Mac OS Big Sur 11.6.6 (Macbook M1). I had Python 3.8 installed on this Macbook and it has been working fine until I upgraded Python today.
Here is the code and the root window does not show in full screen for Python 3.10:
if __name__ == '__main__':
root = tkinter.Tk()
root.attributes('-fullscreen', True)
root.mainloop()
Any help would be much appreciated because I'm stuck. I have also seen other problems with my UI in Python 3.10 so if I'm not able to solve these problems I may revert back to Python 3.8 :(
UPDATE 1 I've noticed that my Macbook makes a bleep sound when I run with the full screen attribute but it does not if I comment out that row.
I've also noticed that it makes the same bleep sound when I type on the keyboard e.g. in an Entry widget. It did not use to do that in Python 3.8, so may be related.
UPDATE 2 I am able to do a somewhat ugly workaround by using a delay and setting the full screen attribute after 250 ms with a root.after(...) function. Then it works. It does not look very nice since empty white backgrounds flash by before the actual program opens.
You need to use root.wm_attributes() instead.
Example
import tkinter as tk
root = tk.Tk()
root.wm_attributes('-fullscreen','true')
root.mainloop()
Yet another way to do this is by calling tcl as follows
root.tk.call("::tk::unsupported::MacWindowStyle", "style", root._w, "plain", "none")
use only either of the methods.

Can't seem to get a window from PYQT5 in Pycharm (macOS Big Sur)

I am using macOS Big Sur beta currently. I have been able to download the libraries via Pycharm 2020.1.2 however, when running my program, no window appears to show what I've been working on.
Example:
Here is a simple line of code I've gotten as an example.
import sys
from PyQt5.QtWidgets import QApplication, QLabel
app = QApplication([])
label = QLabel('Welcome to PYQT5 Tester')
label.show()
app.exec_()
When I run the app, there are no errors and the sole description is my file directory. I am really confused to if I haven't installed anything but any help would be appreciated.
Went down to PyQt5==5.13 and it's working for me now.

Error: no module named gtk.glade

I researched and tried this for two days now and I cannot get gtk to work on Windows 7 with Python 3.4! Whenever I launch my .py file on Python 3.4 with import gtk, I get No module named gtk! I installed pygobject but it did not help. Even gtk3-demo command works in the windows cmd prompt.
I finally got gtk to import (I think) by copying the GTK directory right to C:\Python34\Lib. But now I have a problem with gtk.glade.
Where is this? Where do I copy it from and to where?
You are possibly using an outdated tutorial, see the current Python GTK 3 tutorial for a more up-to-date reference.
In particular, the way to import GTK has changed in GTK3 to:
from gi.repository import Gtk
And instead of libglade, you would use the newer Gtk.Builder class like so:
ui = Gtk.Builder()
ui.add_from_file("my_glade_file.glade")
(you still develop the UI using Glade, it is only how you access it from your program that has changed).

Error loading Qt libraries with Wing and PyQt

I've been trying to get PyQt4 to work on my OSx machine (10.8.5) for some time - I've loaded it on my windows machine with no problem by using an installer.
I have sip 4.8.5, Python 2.7 Qt 4.8.5 loaded on my machine using homebrew.
When I try to debug the following file in WING, I get the following error:
Code from Zetcode as a test
import sys
import QtGui
def main():
app = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('Simple')
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Exception:
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/PyQt4/_qt.so, 2):
Library not loaded: QtDesigner.framework/Versions/4/QtDesigner
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/PyQt4/_qt.so
Reason: image not found
Why is the Qt library not loading? What do I need to do to get the library to load?
Thanks,
-j
I don't personally use homebrew, but I'm pretty sure it installs stuff in /usr/local. From the error message it looks like it is accessing /Library/Frameworks/Python.framework. I also don't use WingIDE, but it looks like it is using a different python install than you want it to. I'm sure there is a way to specify which python it uses.
You probably need to set the Python Executable in Project Properties (from the Project menu) to /usr/local/bin/python -- or whatever the value of sys.executable is in the Python that has PyQt4 installed into it.
Note that in Wing 101 this is done in the Configure Python dialog instead, which is accessed from the Edit menu.

Trouble with simple gtk python script

I am new to python and am trying to run a simple program I found on the web. I have installed the pyGTK All In One Download and cannot (after searching on the web for a month or so) find gtk.py anywhere.
It does not exist on my computer no matter how many times i run pygtk-all-in-one-2.24.2.win32-py2.7.msi
Here is my code
import pygtk
pygtk.require('2.0')
import gtk
class Simple:
def destroy(self, widget, data=None):
gtk.main_quit()
def __init__(self):
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.connect("destroy", self.destroy)
win.set_title("Simple")
win.set_position(gtk.WIN_POS_CENTER)
win.show_all()
Simple()
gtk.main()
I searched this forum and many others as well. If you have this file, could you post the code so I can copy it?
If someone can help I would be very grateful. Thank You for listening.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
It seems that I have found the answer from the following link at http://www.slideshare.net/BaabtraMentoringPartner/importerror-dll-load-failed-is-not-a-valid-win32-application-python-mysql. I uninstalled the 64 bit version and installed the 32 bit version. When I run it from the command line the little window comes up! The error still shows up in Netbeans though so maybe the problem is in the Netbeans IDE?
The gtk code is in
C:\Python27\Lib\site-packages\gtk-2.0
There is no single file named gtk.py. (There is a _gtk.pyd, which is like a dll).
However, you should generally not need to access the source code for the libraries you install. Python will handle that for you when you import gtk, then you can just use those features within your script.
If you have another gtk app (like GIMP) you may have problem with enviroment. Also, I hope that the indentation is broken only here, not in your script. And tell us what is the error.
I guess that using python(64bit ) for Windows 7 was the main problem.
So I uninstalled the 64 bit version and installed the 32 bit version and it seems to work fine now.
Thanks to everyone for your help.
I would like to mark this question as answered but I don't exactly know how.
Uninstall your all-in-one and try with this other all-in-one:
https://sourceforge.net/projects/pygobjectwin32/files/
Then:
import gi
gi.require_version('Gtk', '2.0')
from gi.repository import Gtk

Categories