I'm creating my first GUI app in Python using Tkinter. Very simple script to get some values from a python properties library based on user input. So nothing too complicated
The thing is I'm developing in Linux using i3. So I set windows.attributes('type', 'dialog')
and works like a charm. However, in MS Windows, that line gives an error, and have to comment it.
Commented in i3, it still works, but the window is tilled, not floating.
Is there any way to make it floating in i3 and working in MS-Windows? Any window attributes that I might add to .config/i3/config
to make it floaty and work on MS-Windows?
Thanks
MWE
import tkinter as tk
import numpy as np
window = tk.Tk()
window.title('pytiplier')
window.attributes(
#THIS GIVES ERROR IN WINDOWS
'-type', 'dialog',
)
frm_data = tk.Frame(relief=tk.GROOVE,
borderwidth=2,
)
frm_data.pack()
lbl_number = tk.Label(master=frm_data,
text='Enter a number:',
)
ent_number = tk.Entry(master=frm_data,
width=5,
)
lbl_number.grid(row=0,column=0,sticky='e')
ent_number.grid(row=0,column=1)
frm_compute = tk.Frame()
btn_compute = tk.Button(master=frm_compute,
text="Compute!",
width=15,
height=2,
)
def compute_click(event):
number = float(ent_number.get())
result = np.pi*number
lbl_result['text'] = f'\N{GREEK SMALL LETTER PI}*{number} is {round(result, 4)}'
lbl_result = tk.Label(master=frm_compute,
width=40,
text='Enter a number and press Compute!'
)
lbl_result.pack()
btn_compute.bind("<Button-1>", compute_click)
btn_compute.pack()
frm_compute.pack()
window.mainloop()
Is there any way to make it floating in i3 and working in MS-Windows?
If you need different behavior based on host OS, you might use platform.system
from platform
built-in module, consider simple example:
import platform
host = platform.system()
if host == "Linux":
print("Running on Linux")
elif host == "Windows":
print("Running on Windows")
else:
print("Running on something else")