user9915583
user9915583

Reputation:

How to make a python tkinter app work on android

Im trying to make a tkinter app that works fine on my pc work on my phone.

So far i have tried nothing (apart from a google search). I am new to android app dev but not new to python.

FYI this app is to count the amount of cars, motor bikes and lorries that go past.

import tkinter
from tkinter import *
import tkinter as tk

root = Tk()
root.title('Counter')


def caradd():
    caraddf = open('results.txt', 'a')
    caraddf.writelines('Car\n')
    caraddf.close()

def mbikeadd():
    mbikeaddf = open('results.txt', 'a')
    mbikeaddf.writelines('MotorBike\n')
    mbikeaddf.close()

def Lorryadd():
    Lorryaddf = open('results.txt', 'a')
    Lorryaddf.writelines('Lorry\n')
    Lorryaddf.close()

carframe = Frame(root, bg='red')
carframe.pack()

cartitle = Label(carframe, bg='red', fg='white', text='\nCar\n')
cartitle.pack(side=LEFT)

carbutton = Button(carframe,  bg='red', fg='white', text='\nCar +1\n', command = caradd)
carbutton.pack()

######################################################################

mbikeframe = Frame(root)
mbikeframe.pack()

mbiketitle = Label(mbikeframe, text='\nMotorbike\n')
mbiketitle.pack(side=LEFT)

mbikebutton = Button(mbikeframe, text='\nMotorbike +1\n', command = mbikeadd)
mbikebutton.pack()

######################################################################

Lorryframe = Frame(root)
Lorryframe.pack()

Lorrytitle = Label(Lorryframe, bg='yellow', text='\nLorry\n')
Lorrytitle.pack(side=LEFT)

Lorrybutton = Button(Lorryframe, bg='yellow', text='\nLorry +1\n', command = Lorryadd)
Lorrybutton.pack()

Should work like windows on android

Upvotes: 0

Views: 13388

Answers (4)

Eliud Gonzalez
Eliud Gonzalez

Reputation: 1

the best way to use python on Android, since tkinter is a native desktop application is to use the library kivy, kivy is native to mobile, like Linux, Android and iOS devices, but if you are short on time, you can always translate your script into a 3-party application and use their application there, like pydroid3, I personally enjoy repl.it!

Upvotes: 0

Daniel Greene
Daniel Greene

Reputation: 1

PYDROID 3 works great using TKINTER and due to its scaling capability and the Tkinter font selection you can build apps even for a phone. I have an app that works great on a Tablet and will at least Display on an Android phone with the scaling options. Some mods would be needed for a little larger display but that would be fairly easy to do. The exact same code also runs on a 7" windows tablet. The display looks very close to the same size that I use for my desktop - full window data entry program with many fields 1-1 relationships and many to 1 also. A lot of data on a single screen that saves and reads using CSV files. Sure - it takes some playing around with font sizes, bold/not bold, etc to get everything just right.

Upvotes: 0

Khaled Developer
Khaled Developer

Reputation: 47

You Cannot Export APK With Tkinter , Use Kivy ...

In Kivy , You can Only first Write Source and Export For All Platform ( This Is Cross-platform)

Upvotes: 1

Bananasmoothii
Bananasmoothii

Reputation: 170

to run a tkinter program (or any Python program) on Android, you should use the app Pydroid 3 (on the play store), which has a modified tkinter module for Android and much more. To install this module, go in the app's menu > pip > quick install > tkinter .

Upvotes: 2

Related Questions