Kivy execution error - python

Iam trying to run a simple sample code of Hello World which is as follows:
import kivy
kivy.require('1.8.0') # replace with your current kivy version !
from kivy.app import App
from kivy.uix.button import Button
class MyApp(App):
def build(self):
return Button(text='Hello World')
if __name__ == '__main__':
MyApp().run()
and i have saved this as hello.py which then i run by using kivy-1.8.0 which in turn gives me an error message titled Kivy Fatal Error and the rest of the description is in Chinese,Japanese or Korean language.
Is there a problem of graphics card? or
Is there any other way to a Kivy application
please help.

Please post the full terminal output from when the app is run.
I don't remember what the funny character message means (it's nonsense, not real text), but I think it indicates a too-low opengl version. The appearance of the garbled message is itself a bug that I think is fixed in kivy master.

Possible issues with kivy (and python):
Indentation issues: make doubly sure that your indents are consistent: they should all be the same. If you are using a tab, make sure it is a tab everywhere. If you are using multiple spaces make sure they are the same number everywhere.
A more kivy specific issue: try to comment out line 2 (kivy.require('1.8.0')). You may not have the correct version of kivy installed. Alternatively, decrease that number (1.0.6 should be more than enough for what you are doing in this simple application).
I don't know what the issue could be with the language you get the message in. Perhaps you installed some weird distribution, or selected some language pack that it is defaulting to.

Related

Applying LiveServer Logic for Tkinter File

The people who are familiar with the Live Server of VS Code, would have easily understood what is the main motive of this question.
But for others, here's the explanation:
Main motive of Live Server is to Automatically Reload Your Site on Save in web development! (Which get changed for python tkinter).
When ever I change something in my python file which contains tkinter code, the change should be reflected in the main window (the main window should not re-open to reflect the changes).
I have tried to search on web as well as on stack over flow, but all the results are for updating value in entry, label, buttons etc. But what I want is, the whole window should be updated when ever I change something in my main file, and the main window should not be reopened to do so. So in short, updating whole window without closing it, on every changes in the main file or automatically reload your program on save without reopening!
What have I tried?:
I tried to detect change in file using os.getsize which satisfied the first part of my question, but however I am not able to solve the second part i.e window should not be closed.
import os
main__tkinter_filename="myfile.py"
initial_filesize=os.path.getsize(main_tkinter_filename) # Getting size of the file for
# comparison.
while 1:
final_filesize=os.path.getsize(main_tkinter_filename)
if final_filsize<intial_filesize or final_filesize>initial_filesize:
webbrowser.open(main_tkinter_filename)
Example:
from tkinter import *
root=Tk()
root.mainloop
results in the below GUI:
If i have added a=Label(text='text')anda.pack() after root=Tk(), it should show me the label, and if i have removed the same code, it should remove them.
I will answer your question by the best of my understanding,
I have some (a few projects of my own, still way too limited) experience with flutter which has hot-reload feature (same as you described above, which you want with python, mainly tkinter), I recently switched to python for gui (Loved it!), so I would like to share my research here:
I was successfully able to set up hot-reload both with kivy (kivymd hot reload, which comes with watchdog and kaki, which works real-time), and with tkinter, while there is a hitch with the later, you will have to press Ctrl + R as to reload the tkinter window, but it works without having to re-run the python program, I will leave the link to the found resources here, hope it helps with your query!
To setup hot-reload with tkinter (requires Ctrl + R), please refer here.
To setup hot-reload with kivy/kivymd (real-time), which I personally prefer, you can find the official docs here.
To mention, I use the above on Manjaro (Arch linux) with pycharm, atom, but I have also tried and have made it run successfully on Windows 10 with vs code (worked like charm)
Hope I could be of help! If you face any problem regarding the same, please feel free to ask! Thanks!
After digging around I have finally found out a way to implement hot reload feature (which #Stange answers provides) but just updating the selected frame or code.
The basic idea is constanly reading the file and executing the selected code, and removing the object in a list which are meant to be removed.
# Live Checker.py
import keyboard
while 1:
if keyboard.is_pressed("Ctrl+r"):
with open('test.py','r') as file:
file_data=file.read()
file_data_start_index=file_data.find("'#Start#'")
file_data_end_index=file_data.find("'#End#'")
exec_command=file_data[file_data_start_index:file_data_end_index]
with open('exec_log.txt','w') as txt_file:
txt_file.write(exec_command)
Here I am constantly checking if if ctrl+r key is pressed, and if pressed
it reads the file,
writes the selected code from the file into a txt file.
I have specified the start and end of the code to be updated by #Start# and #End# respectively.
# Main.py
def check():
with open('exec_log.txt','r') as exec_c:
exec_command=exec_c.read()
if len(exec_command)==0:
pass
else:
print(exec_command)
exec('for i in root.winfo_children():i.destroy()\n'+exec_command)
print('exec')
with open('exec_log.txt','w') as exec_c:
pass
root.update()
root.after(100,check)
root.after(100,check)
And in the main file, i have added the above code which continusly check if exec_log.txt file has any changes, and if changes are there, then it executes them and all so destroys the widget specified in the remove_list.
This is just a temporary solution which in my case helps me to implement the hot reload feature in tkinter.

How to fix "inline error" for Kivymd MDDataTable python3

I am using Python3 and kivymd for my python app.
I am trying to use the MDDataTable module from kivymd but whenever I run it, it gives this "inline error". Is there anyway to fix this?
I already tried reinstalling the kivymd module but that doesn't solve the problem
Thank you for reading this
Problem image
You are giving wrong value to orientation
Valid orientations are ‘lr-tb’, ‘tb-lr’, ‘rl-tb’, ‘tb-rl’, ‘lr-bt’, ‘bt-lr’, ‘rl-bt’ ‘bt-rl’.
‘lr’ means Left to Right. ‘rl’ means Right to Left. ‘tb’ means Top to Bottom. ‘bt’ means Bottom to Top.
See docs:
https://kivy.org/doc/stable/api-kivy.uix.gridlayout.html#kivy.uix.gridlayout.GridLayout.orientation

Kivy isn't showing (Bengali) Unicode character properly

Currently I am Working on a Kivy desktop application but I am facing a problem while trying to display unicode characters in Bengali in my application's Label and Button Text. Every time I'm getting output like the image below. I have tried different fonts such as SolaimanLipi.ttf, kalpurush.ttf, NikoshBAN.ttf but still no luck. I am using a Windows PC. The same text in the same font displays correctly outside of Kivy; it works fine in all text editors and to make sure I have tested in a Java Swing desktop application, too.
Can any one please describe what is the problem? What can i do to solve it?
Expected Output:
Program Output:
#-- coding: utf-8 --
from kivy.base import runTouchApp
from kivy.lang import Builder
runTouchApp(Builder.load_string("""
#:import sp kivy.metrics.sp
Label:
text: 'সকালে'
font_size: sp(50)
font_name: "SolaimanLipi.ttf"
"""))
There is a bug in Kivy which has been open since 2014 (!) - https://github.com/kivy/kivy/issues/2669
To the extent that I can understand the discussion and the current status, the developer is looking for a solution still.
Languages such as Tamil require reshaping, a process which is not supported in our current providers. I'm working on a new text provider using Pango as an option to provide this support on Linux (and probably OSX).
-- kived in 2014
This (from 2017) seems relevant, too, but also vaguely stale: https://github.com/kivy/kivy/issues/4902
Unicode text can be converted to Bijoy (ANSI) text and can be used easily in Kivy with the use of [font] tag like this:
text = "[font=font/SutonnyMJ]Avwg evsjvq K_v ewj[/font] means I speak Bangla"
This repo provides code and instructions related to Unicode to Bijoy (ANSI) conversion in Kivy. Not a perfect solution, but most of the apps will meet their need.

tkinter simpledialog not working on Mac 10.14

I'm creating a UI with python 3.7 with tkinter. I have a button that should open a dialog and ask for a string input, in windows it works entirely as expected but for some reason it won't work on any of 3 Macs I've tried. On the Macs the main window goes gray on top and you can't interact with it, so it's as if a dialog window has opened, but the dialog window is nowhere to be found. Python is not crashing or giving any error messages either. It's baffling to me that I have not been able to find any similar problems searching online.
The button calls this method:
def add_goal(self):
newgoal = simpledialog.askstring("Input", "What goal would you like to begin tracking?", parent=self.root)
self.goal_list.goals.append(goal.Goal(newgoal,0,0))
self.set_listbox()
print(self.goal_list)
I have tested the button with only a print statement so I know the button works.
I have also tested the button with only the simpledialog line so I know the other parts aren't causing a problem. I have also tried simpledialog.askinteger just to see and that didn't work either.
If relevant I'm doing from tkinter import simpledialog at the top.
And again this all works perfectly fine on windows.
Thanks for any help, I can post the entire code if anyone wants but I don't think any of it is relevant.
Was using root.attributes("-topmost", True), the code was derived from a program that was meant to be at the front of the screen at all times which is why that line was there to begin with, but I realized it was no longer necessary and it seems to be the source of the problem.

Using External kv file

I am trying to use an external kv file for my program and it is not working. It goes up to a certain point then stops and gives me an error message. The version of Python I am using is 3.5 and the version of kivy I am using is kivy 1.9.1.
This is the code I used in the .py file:
Here is what it displays when it runs:
I don't understand what going on. I am open to elaborate more on this question if it is not clear yet.
In your build function you must return a widget. Instead you return a class of a widget (which is not a widget in itself). Replace Label by Label() which returns an instance of the class Label.

Categories

Resources