This code in python 2.7.3 work in windows xp, not work in Ubuntu Unity.
How make in ubuntu window transparency.
# -*- coding: UTF-8 -*-
from Tkinter import Tk
window = Tk()
window.wm_attributes('-alpha',0.8)
window.geometry('500x500+200+211')
window.mainloop()
Try this instead:
from Tkinter import Tk
window = Tk()
window.wait_visibility(window)
window.wm_attributes('-alpha',0.8)
window.geometry('500x500+200+211')
window.mainloop()
Related
When running on Win10 the following script against the Python 3.8.2 command line, it works just fine, opens a Tk window and displays a triangle:
from tkinter import *
tk = Tk()
canvas = Canvas(tk, width=400, height=400)
canvas.pack()
canvas.create_polygon(10, 10, 10, 60, 50, 35)
However, when running the same script from the PowerShell command line with
& "C:/Program Files (x86)/Python38-32/python.exe" c:/Users/Me/sample.py
The script terminates without error and without opening the Tk window.
How can I get the Tk window to open while calling the Python interpreter from PowerShell command line?
I believe the issue is that you forgot to add
tk.mainloop()
at the end of your script which keeps the window running.
Let me know if adding this fixes your problem.
I am learning about Python3 scripting/programming with this config:
My PC on win10
remote PC under my tv with Debian 9 on it.
I installed xrdp to get a remote graphical UI to play around with Tkinter.
I wrote this very simple script :
#!/usr/bin/env python3
#coding: utf-8
from tkinter import *
fenetre = Tk()
label = Label(fenetre, text="Hello World")
label.pack()
fenetre.mainloop()
But I hit an issue:
_tkinter.TclError: couldn't connect to display ":10.0"
I understand that's linked to xrdp because if I try it physically on the pc it works well.
Any idea or workaround? :/
Thank you !
I used this with Python3.10 on Ubuntu 20.4 with xrdp and hyper-v running on Windows 11 and it works.
import tkinter as tk
window = tk.Tk()
label = tk.Label(window, text="Hello World")
label.pack()
window.mainloop()
I am starting to learn a bit about Python. I am trying to convert Python Tkinter app into exe file. Converting to exe works fine when Tkinter is not involved. I tryed sample file of setup.py and Tkinter app that you can find on official website of cx_Freeze [http://cx-freeze.readthedocs.io/en/latest/index.html] but still geting a lot of errors [like: KeyError: 'TCL_LIBRARY'] in CMD when runing build command. On official website is stated that Python 3.6 is supported.
Here is official example of setup.py:
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
executables = [
Executable('app.py', base=base)
]
setup(name='simple_Tkinter',
version='0.1',
description='Sample cx_Freeze Tkinter script',
executables=executables
)
And here is official example of test Tkinter app:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
try:
from tkinter import Tk, Label, Button, BOTTOM
except ImportError:
from Tkinter import Tk, Label, Button, BOTTOM
root = Tk()
root.title('Button')
Label(text='I am a button').pack(pady=15)
Button(text='Button').pack(side=BOTTOM)
root.mainloop()
Instead of cx_freeze you could try and use Pyinstaller it will do the exact same job you are trying to accomplish.
From pip go ahead and type
pip install pyinstaller and then in your programs directory run pyinstaller yourprogram.py
I tried to use one icon from:
https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
PyQt4 set windows taskbar icon
But it does not show up on the window:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
import sys
from PyQt4.QtGui import *
# Create an PyQT4 application object.
a = QApplication(sys.argv)
# The QWidget widget is the base class of all user interface objects in PyQt4.
w = QWidget()
# Set window size.
w.resize(820, 240)
# Set window title
w.setWindowTitle("Hello World!")
# https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
undoicon = QIcon.fromTheme("camera-web")
w.setWindowIcon(undoicon)
# Show window
w.show()
sys.exit(a.exec_())
I am on Windows 10 with:
Anaconda conda --version -> conda 4.3.18
Python python --version -> Python 2.7.13 :: Anaconda custom (32-bit)
The documentation says
By default, only X11 will support themed icons. In order to use themed icons on Mac and Windows, you will have to bundle a compliant theme in one of your themeSearchPaths() and set the appropriate themeName().
This function was introduced in Qt 4.6.
Since you would need to gather a theme anyways to ship with the application, you could also just choose to collect some icons and specify the files directly.
w.setWindowIcon( QtGui.QIcon("folder.png") )
To use Tkinter to open a dialog box I have the following Python 2.7 code:
from Tkinkter import Tk
from tkFileDialog import asksavesfinename
root = Tk().withdraw()
f = asksaveaskfilename()
This works just fine if I run the program under Idle.
However, if I run it, as root, from the LXTerminal, it fails with the exception “Client is not authorized to connect to Server…..”
Any help will be appreciated, Thanks.