How print to printer with Popen and GUI tkinter

By : eM. Key

I use code from this question for printing to thermal EPSON TM-T82 printer but when I modified it with tkinter and mainloop() python not direcly printout my data until I close my layout GUI. I want this script can print out my data without I close layout GUI.

This is my code:

import subprocess
from Tkinter import *

class tes_print:
   def __init__(self):

   def printData(self):
       data = " MY TEXT "
       lpr = subprocess.Popen("/usr/bin/lpr", stdin=subprocess.PIPE, shell=True)

root = Tk()
app2 = tes_print()
By : eM. Key


You are experiencing buffering. The write will write to a buffer which is not actually passed on to lpr until it fills up or you explicitly flush it.

Running lpr.communicate() will flush it and allow lpr to run to completion.

lpr = subprocess.Popen(['lpr'], stdin=subprocess.PIPE)
stdout, stderr = lpr.communicate(input=data)
By : tripleee

Regardless of iOS 10, you should start your location updating only if the permission was granted, you should also check if the permission is already granted before requesting permissions:

    self.locationManager=[[CLLocationManager alloc]init];
    // Check for current permissions
    [self checkLocationAuth:[CLLocationManager authorizationStatus]];

-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
    [self checkLocationAuth:status];

    switch (status) {
        case kCLAuthorizationStatusAuthorizedWhenInUse:
        case kCLAuthorizationStatusAuthorizedAlways:
            [self.locationManager startUpdatingLocation];
            // did not ask for permission, ask now
        case kCLAuthorizationStatusNotDetermined:
            if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
                [self.locationManager requestWhenInUseAuthorization];
            } else { // iOS < 8? implicitly request permission
                [self.locationManager startUpdatingLocation];
        // Also need to handle failures, etc
By : iMoses

I think preg_replace() is the better solution here as it will allow you to remove anything except alphabetical letters (as you requested in your comments):

$numChars = strlen(preg_replace("/[^A-Za-z]/", '', $getexpression));
By : icecub

This video can help you solving your question :)
By: admin