I wanna learn kivy. But on youtube, everyone run it by creating class and have to run it by classname().run(). I want to simplify to run kivy like tkinter, I always use root=Tk() to create and design window. Can anyone know how to use kivy like tkinter/root=Tk()??
Here is my code, which I always use with tkinter:
from tkinter import *
root=Tk()
root.title('Stackoverflow')
root.config(bg='white')
root.geometry('400x400')
Label(root,text='Welcome to This Question, Please Answer This',font='20',bg='white').place(x=30,y=170)
root.mainloop()
No, Kivy doesn't have the same API as tkinter and I'm not aware of anyone having written a wrapper package to expose a similar API.
Also, I would encourage you not to worry about this - it's normal that different packages have different APIs, and in general these APIs are designed to efficiently express how the toolkit should be used. It is normal to expect to learn how a new package works.
Installing Kivy
python -m pip install --upgrade pip setuptools virtualenv
python -m virtualenv kivy_program
kivy_program/Scrtips/activate
source kivy_program/Scripts/activate
source kivy_program/Scripts/activate
python -m pip install kivy[base] kivy_example
Code
from kivy.app import App
class myapp(App):
pass
# Code
if __name__ == '__main__':
window = myapp()
Related
So I have made a App using Tkinter and compiled it, everything works fine on my end. However when I sent it to a friend the tkinker app itself ran fine (ie. the gui ran and responded) BUT certain parts didn't work.
So part of the app allows you to ping an ip and that works fine and updates the tkinter Listbox. What doesn't work is running the discord bot and network sniffing using the scapy module.
Now that's most likely because he doesn't have them modules and I can make the app check for them and download them but what I can't figure out is how to check and install pip through the tkinter app as he doesn't even have pip installed. How would I do this the only way I know how to install modules is through pip
SUMMORY QUESTION:
so how do I check and install pip if missing on a tkinter app
Currently working on Python (version 3.7.8) programming, using PyCharm software.
I would like to install tkinter for future python projects with future and pip plugins.
I tried to follow a series of tutorials, but all I get is error messages, such as tracebacks.
Source code as follows:
import tkinter
top = tkinter.Tk()
top.mainloop()
After hours of trial an error, I hope, somebody can help me here.
I got my MacBook Air (M1, 2020) and want to use kivy for python-programming on it.
When I first bought the Laptop 3 month ago it took a lot of work to find a way to run kivy/ execute my kivy-code on it.
Finally, I ended up with the Kivy.app version which created [please excuse my limited understanding...] a Application, I could drag my python-files on or execute the files via the command line like kivy main.py. The "usual" way of simply installing kivy via pipdid never work (as far as I understood because the presented wheel is not compatible with the M1-Chip).
Now, I upgraded my MacOS to Monterey, which crashed everything. I can't even give a lot of information about what's broken. when I try to drag files on the Kivy-Application simply nothing happens. Executing any file (even a simple print("Hello")via the command line (like kivy main.py) results in
kivy
/Applications/Kivy.app/Contents/Resources/venv/bin /Applications/Kivy.app/Contents/Resources
/Applications/Kivy.app/Contents/Resources ImportError: No module named site
Since I don't use any special setup, just the fresh updated MacOS in it's newest version and python (installed via homebrew and already reinstalled after updating the OS) I hope anyone with more understanding of the how's and why's than me already fixed this problem for him/her self and can enlighten me.
I could run kivy on MacOS with M1 chip using rosetta 2.
Install rosetta 2
softwareupdate --install-rosetta
Start a terminal with rosetta. Right click to /Applications/iTerm or /Applicatins/Utilities/Terminal > Get Info > Open Using Rosetta
Create a fresh virtualenv. Install requirements
pip install kivy[base] kivy-examples
Run main.py (python main.py)
main.py
import kivy
kivy.require('2.0.0')
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text='Hello world')
if __name__ == '__main__':
MyApp().run()
Do you have Rosetta2 installed? I ask because Kivy.app is an Intel Application and cannot work without that.
Install CLI Kivy Tools for Apple M1 Chip Mac
You need Homebrew and XCode, follow this guide:
Dependencies (for macOS); you need one more dependency:
brew install ffmpeg
Install step; see "Development install".
After calling either:
python setup.py build_ext --inplace
...or your "make" command, you can call sudo make install to build Kivy in your Python3 folder and remove the folder you downloaded previously.
If, during the build, you have an error due to missing cython, you need to install cython from the source; you can do this here.
P.S., I don't know how kivy.app works, but I use VSCode + Kivy CLI 2.1.0dev and when I launch the kivy app (with imported module of kivy); it launches with kivy, but when I try to launch the print('hello') program, it only launches from the console (not with kivy).
Been trying for days to figure out why this won't work. I've tried this on 3 different freshly new Linux Mint distros and I get this error every time.
I'm trying to complete step 1 for the GUI tutorial on rasperry pi's website. https://www.raspberrypi.org/learning/getting-started-with-guis/
I've simply done the following:
Verified Python3 is installed and up to date
Installed guizero
from guizero import App
app = App(title="Hello world")
app.display()
The error message follows attempting to run this file. (Title is complete error message)
Edit:
Yes, I am using Python 3. I verified Python 3 is installed and run the script using Python 3. I installed guizero via pip3.
Tkinter only comes as standard on windows. The default GUI module for Linux is Gtk. Tkinter is available on apt under the name Python-Tk
python3:
sudo apt-get install python3-tk
I'd like to import the "requests" library into my Kivy application. How do I go about that? Simply giving import requests is not working out.
Edit:
I'm using Kivy on Mac OS X, 10.10.3.
For a Mac specific answer, I tried
kivy -m pip install requests.
This post helped me out.
If you're using windows with kivy's portable package, I think you can get a shell with kivy's env by running the kivy executable. Assuming so, I think you can run pip install requests in this shell to install it to kivy's environment.
Edit: I see you've now noted you are using OS X, but something similar may be true. I don't know about this though.