Bob Blomquist
Published © GPL3+

Pinball Touchscreen Display

The third project about an Arduino powered pinball machine. This project describes how to add a touchscreen unit to handle high scores.

AdvancedFull instructions provided20 hours1,833
Pinball Touchscreen Display

Things used in this project

Story

Read more

Code

Arduino Code

Arduino
Used to control pinball machine game play
  const int TxPin = 17;
  long Score = 0;
  long OldScore = 0;
  long Target = 1;
  long Pop = 1;
  long Roll = 10;
  int Targets[8];
  int Rolls[3];
  int Pops[4];
  int Milli = 10;
  int Sum = 0;
  int Flash = 100;
  int Ball = 0;
  int i=0;
  int Shot = 0;
  int Lost = 0;
  int Pressure = 1024;
  
#include <SoftwareSerial.h>;
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);
#include <AltSoftSerial.h>    // Arduino build environment requires this
#include <wavTrigger.h>
wavTrigger wTrig;       

void setup() {
  /* Words without an s are the value achieved by interacting with a device. 
   * Works with an s keep track of which individual ones were interacted with. 
   * The latter is needed to determine when all have been hit and the value needs upgrading
   * and the lights need turning off.
   */
   Serial.begin(115200);
  
  pinMode(TxPin, OUTPUT);
  digitalWrite(TxPin, HIGH);
  mySerial.begin(9600);
  mySerial.write(12);                 // Clear             
  mySerial.write(17);                 // Turn backlight on
  wTrig.start();
   // If the Uno is powering the WAV Trigger, we should wait for the WAV Trigger
  //  to finish reset before trying to send commands.
  delay(1000);
  
  // If we're not powering the WAV Trigger, send a stop-all command in case it
  //  was already playing tracks. If we are powering the WAV Trigger, it doesn't
  //  hurt to do this.
  wTrig.stopAllTracks();
  wTrig.masterGain(0);                  // Reset the master gain to 0dB                               
   
  //target inputs
  pinMode(2,INPUT_PULLUP);
  pinMode(3,INPUT_PULLUP);
  pinMode(4,INPUT_PULLUP);
  pinMode(5,INPUT_PULLUP);
  pinMode(6,INPUT_PULLUP);
  pinMode(7,INPUT_PULLUP);
  pinMode(8,INPUT_PULLUP);
  pinMode(9,INPUT_PULLUP);
  //rollover inputs
  pinMode(10,INPUT_PULLUP);
  pinMode(11,INPUT_PULLUP);
  pinMode(12,INPUT_PULLUP);
  //lower ball shot switch
  pinMode(15,INPUT_PULLUP);
  //upper ball shot switch
  pinMode(16,INPUT_PULLUP);
  //lcd output
  pinMode(17,OUTPUT);
  //target lights, respective
  pinMode(32,OUTPUT);
  pinMode(33,OUTPUT);
  pinMode(34,OUTPUT);
  pinMode(35,OUTPUT);
  pinMode(36,OUTPUT);
  pinMode(37,OUTPUT);
  pinMode(38,OUTPUT);
  pinMode(39,OUTPUT);
  //rollover lights, respective
  pinMode(40,OUTPUT);
  pinMode(41,OUTPUT);
  pinMode(42,OUTPUT);
  //pop bumper lights
  pinMode(50,OUTPUT);
  pinMode(51,OUTPUT);
  pinMode(52,OUTPUT);
  pinMode(53,OUTPUT);
  
}

void loop() {
  // put your main code here, to run repeatedly:
  //If a pull-down resistor is used, the input pin will be LOW when the switch is open and HIGH when the switch is closed. 
  //check if a target was hit

//****** Targets *****

  for (int i=0; i<8; i++){
    if (digitalRead(i+2) == LOW){
      //Target activated
      Targets[i]=1;
      Score = Score + Target;
      Serial.print(Score);
      Serial.print(", ");
      Serial.print(Roll);
      Serial.print(", ");
      Serial.print(Pop);
      Serial.print(", ");
      Serial.print(Target);
      Serial.print(", ");
      Serial.println(Ball);
      //turn on Target light
      digitalWrite(i+32,HIGH);
      //delay so as not get multiple points for one hit
      wTrig.trackPlayPoly(8);
      delay(Milli);
      break;
    }
  }
  Sum = 0;  
  for (int i=0; i<8; i++){
    Sum = Sum + Targets[i];
  }
  if (Sum == 8){
    //all Targets lit, so flash and then turn off.
    for (int j=0; j<3; j++){
      for (int i=0; i<8; i++){
        digitalWrite(i+32, LOW);
      }
      delay(Flash);
      for (int i=0; i<8; i++){
        digitalWrite(i+32, HIGH);
      }
      delay(Flash);
    }
    for (int i=0; i<8; i++){
      digitalWrite(i+32, LOW);
      Targets[i]=0;
    } 
    delay(Flash);   
    //Multiply target value by 10
    Target = Target * 5;
    Serial.print(Score);
      Serial.print(", ");
      Serial.print(Roll);
      Serial.print(", ");
      Serial.print(Pop);
      Serial.print(", ");
      Serial.print(Target);
      Serial.print(", ");
      Serial.println(Ball);
    //goto Skip;  
  }
  

// ***********  Rollovers *********

  
   for (int i=0; i<3; i++){
    if (digitalRead(i+10) == LOW){
      //rollover activated
      Rolls[i]=1;
      Score = Score + Roll;
      Serial.print(Score);
      Serial.print(", ");
      Serial.print(Roll);
      Serial.print(", ");
      Serial.print(Pop);
      Serial.print(", ");
      Serial.print(Target);
      Serial.print(", ");
      Serial.println(Ball);
      //turn on rollover light
      digitalWrite(i+40,HIGH);
      //delay so as not get multiple points for one hit
      wTrig.trackPlayPoly(6);
      delay(Milli);
      break;
    }
  }
  Sum = 0;  
  for (int i=0; i<3; i++){
    Sum = Sum + Rolls[i];
  }
  if (Sum == 3){
    //all rollovers lit, so flash and then turn off.
    for (int j=0; j<3; j++){
      for (int i=0; i<3; i++){
        digitalWrite(i+40, LOW);
      }
      delay(Flash);
      for (int i=0; i<3; i++){
        digitalWrite(i+40, HIGH);
      }
      delay(Flash);
    }
    for (int i=0; i<3; i++){
      digitalWrite(i+40, LOW);
      Rolls[i]=0;
    } 
    delay(Flash);   
    //Multiply score by 2
    Score = Score * 2;
    Roll = Roll * 10;
    Serial.print(Score);
      Serial.print(", ");
      Serial.print(Roll);
      Serial.print(", ");
      Serial.print(Pop);
      Serial.print(", ");
      Serial.print(Target);
      Serial.print(", ");
      Serial.println(Ball);
    //goto Skip;  
  }
  
  //**********  Pop Bumpers **********
  
   for (int i=0; i<4; i++){
    if (analogRead(i) > 500){
      //pop activated
      Pops[i]=1;
      Score = Score + Pop;
      Serial.print(Score);
      Serial.print(", ");
      Serial.print(Roll);
      Serial.print(", ");
      Serial.print(Pop);
      Serial.print(", ");
      Serial.print(Target);
      Serial.print(", ");
      Serial.println(Ball);
      //turn on pop bumper light
      digitalWrite(i+50,HIGH);
      //delay so as not get multiple points for one hit
      wTrig.trackPlayPoly(7);
      delay(Milli);
      break;
    }
  }
  Sum = 0;  
  for (int i=0; i<4; i++){
    Sum = Sum + Pops[i];
  }
  if (Sum == 4){
    //all pop bumpers lit, so flash and then turn off.
    for (int j=0; j<3; j++){
      for (int i=0; i<4; i++){
        digitalWrite(i+50, LOW);
      }
      delay(Flash);
      for (int i=0; i<4; i++){
        digitalWrite(i+50, HIGH);
      }
      delay(Flash);
    }
    for (int i=0; i<4; i++){
      digitalWrite(i+50, LOW);
      Pops[i]=0;
    } 
    delay(Flash);   
    //Multiply target value by 10
    Pop = Pop * 2;
    Serial.print(Score);
    Serial.print(", ");
    Serial.print(Roll);
    Serial.print(", ");
    Serial.print(Pop);
    Serial.print(", ");
    Serial.print(Target);
    Serial.print(", ");
    Serial.println(Ball);
    //goto Skip;  
  }
Skip:
 
  if (digitalRead(15) == LOW){   
    //ball hit lower alley switch
    //if not already done so, increase Ball
    if (Shot == 0){
        if (Ball == 0){
          Score = 0;
        }
      //Set Lost = 0 since not on pressure pad
      Lost = 0;
      Pressure = analogRead(7) + 25;  
      //set OldScore so as to reprint ball value on LCD
      OldScore =-1;
      Ball = Ball + 1;
      Serial.print(Score);
      Serial.print(", ");
      Serial.print(Roll);
      Serial.print(", ");
      Serial.print(Pop);
      Serial.print(", ");
      Serial.print(Target);
      Serial.print(", ");
      Serial.println(Ball);
      wTrig.stopAllTracks();
      delay(Milli);    
      wTrig.trackPlayPoly(Ball);
      Shot = 1;
      delay(Milli);
    }
  }
  if (analogRead(7) > Pressure){
    //ball on pressure pad
    Shot = 0;
    if (Lost == 0){
      //mySerial.print(analogRead(7));
      //Score = Score + 100;
      Lost = 1;
      if (Ball == 5){
        //Game Over
        //flash rollovers and then turn off.
        for (int j=0; j<3; j++){
          for (int i=0; i<3; i++){
            digitalWrite(i+40, LOW);
          }
          delay(Flash);
          for (int i=0; i<3; i++){
            digitalWrite(i+40, HIGH);
          }
          delay(Flash);
        }
        for (int i=0; i<3; i++){
          digitalWrite(i+40, LOW);
          Rolls[i]=0;
        } 
        // flash pop bumpers and then turn off
        for (int j=0; j<3; j++){
          for (int i=0; i<4; i++){
            digitalWrite(i+50, LOW);
          }
          delay(Flash);
          for (int i=0; i<4; i++){
            digitalWrite(i+50, HIGH);
          }
          delay(Flash);
        }
        for (int i=0; i<4; i++){
          digitalWrite(i+50, LOW);
          Pops[i]=0;
        } 
        //Flash Targets and then turn off.
        for (int j=0; j<3; j++){
          for (int i=0; i<8; i++){
            digitalWrite(i+32, LOW);
          }
          delay(Flash);
          for (int i=0; i<8; i++){
            digitalWrite(i+32, HIGH);
          }
          delay(Flash);
        }
        for (int i=0; i<8; i++){
          digitalWrite(i+32, LOW);
          Targets[i]=0;
        } 
        mySerial.write(12);                 // Clear
        delay(5);
        // Required delay
        mySerial.print(Score);  // First line
        mySerial.write(13);                 // Form feed
        mySerial.print("Game Over!!!");   // Second line
        Serial.print(Score);
        Serial.print(", ");
        Serial.print(Roll);
        Serial.print(", ");
        Serial.print(Pop);
        Serial.print(", ");
        Serial.print(Target);
        Serial.print(", ");
        Ball = 0;
        //send -1 to Raspberry Pi to indicate game over
        Serial.println(-1);
        Target = 1;
        Roll = 1;
        Pop = 1;
        wTrig.stopAllTracks();
        delay(Milli);
        wTrig.trackPlayPoly(10);
        delay(Milli);
      }
    }
  }
  //print to LCD
  if (Score != OldScore){ 
  mySerial.write(12);                 // Clear
  delay(5);                           // Required delay
  //mySerial.print(analogRead(7));
  mySerial.print(Score);  // First line
  mySerial.write(13);                 // Form feed
  mySerial.print("Ball = ");   // Second line
  mySerial.print(Ball);
  OldScore = Score;
  }
}

Raspberry Pi Code

Python
Used to control the Raspberry Pi Touchscreen for displaying high scores and game values
from tkinter import*
import tkinter as tk    # for the GUI
import serial   # for communication with serial port
import datetime # for time stuff
import _thread    # for parallel computing
#import time

#prepare variables
Scores = []
LabelText=[]
Lbl=[]
Names = []
btn= []
Dates = []
number = 0
MinHigh = 0
CurrentScore = 0
Targets = 0
Pops = 0
Rolls =0

Ball = "0"
DisplayScreen = 1
#need a dummy tuple for threading
DummyTuple = ();
n=0
# open file and read stored high scores
file = open("/home/pi/Documents/Python Files/Pinball Files/text.txt", "r")
for n in range(0,10):
    Score = file.readline()
    Name = file.readline()
    
    Date = file.readline()
    #get rid of line feeds
    Score = Score[0:len(Score)-1]
    Name = Name[0:len(Name)-1]
    Date = Date[0:len(Date)-1]
    #append value to array variable
    
    Scores.append(Score)
    Names.append(Name)
    Dates.append(Date)
file.close()          
# Delete any 'Today's High Scores" that are no longer from today
for n in range(5,10):
    if Dates[n]!= str(datetime.date.today()):
        Dates[n]= ""
        Names[n]= "N/A"
        Scores[n]= 0
            

    
def SortScores():
    #need to sort scores
    global CurrentScore
    global Scores
    global Names
    global Dates
    global PlayerName
    global Ball
    global DisplayScreen
    #first sort Today's high scores
    #These are stored in the three arrays below with indexes 5 to 9
    Scores[9]=str(CurrentScore)
    Names[9]=PlayerName.get()
    Dates[9]=str(datetime.date.today())
    if int(Scores[9])>int(Scores[8]):
        temp = Scores[8]
        Scores[8] = Scores[9]
        Scores[9]= temp
        temp = Names[8]
        Names[8]=Names[9]
        Names[9] = temp
        temp = Dates[8]
        Dates[8] = Dates[9]
        Dates[9]= temp
    if int(Scores[8])>int(Scores[7]):
        temp = Scores[7]
        Scores[7] = Scores[8]
        Scores[8]= temp
        temp = Names[7]
        Names[7]=Names[8]
        Names[8] = temp
        temp = Dates[7]
        Dates[7] = Dates[8]
        Dates[8]= temp        
    if int(Scores[7])>int(Scores[6]):
        temp = Scores[6]
        Scores[6] = Scores[7]
        Scores[7]= temp
        temp = Names[6]
        Names[6]=Names[7]
        Names[7] = temp
        temp = Dates[6]
        Dates[6] = Dates[7]
        Dates[7]= temp
    if int(Scores[6])>int(Scores[5]):
        temp = Scores[5]
        Scores[5] = Scores[6]
        Scores[6]= temp
        temp = Names[5]
        Names[5]=Names[6]
        Names[6] = temp
        temp = Dates[5]
        Dates[5] = Dates[6]
        Dates[6]= temp
        #Now sort All Time High Scores
        #These have indexes 0 to 4
    if int(CurrentScore)>int(Scores[4]):
        Scores[4] = CurrentScore
        Names[4]=PlayerName.get()
        Dates[4] = str(datetime.date.today())
    if int(Scores[4])>int(Scores[3]):
        temp = Scores[3]
        Scores[3] = Scores[4]
        Scores[4]= temp
        temp = Names[3]
        Names[3]=Names[4]
        Names[4] = temp
        temp = Dates[3]
        Dates[3] = Dates[4]
        Dates[4]= temp        
    if int(Scores[3])>int(Scores[2]):
        temp = Scores[2]
        Scores[2] = Scores[3]
        Scores[3]= temp
        temp = Names[2]
        Names[2]=Names[3]
        Names[3] = temp
        temp = Dates[2]
        Dates[2] = Dates[3]
        Dates[3]= temp
    if int(Scores[2])>int(Scores[1]):
        temp = Scores[1]
        Scores[1] = Scores[2]
        Scores[2]= temp
        temp = Names[1]
        Names[1]=Names[2]
        Names[2] = temp
        temp = Dates[1]
        Dates[1] = Dates[1]
        Dates[2]= temp
    if int(Scores[1])>int(Scores[0]):
        temp = Scores[0]
        Scores[0] = Scores[1]
        Scores[1]= temp
        temp = Names[0]
        Names[0]=Names[1]
        Names[1] = temp
        temp = Dates[0]
        Dates[0] = Dates[1]
        Dates[1]= temp    
        DisplayScreen = 0
    #Save data as a text file
    file = open("/home/pi/Documents/Python Files/Pinball Files/text.txt", "w")
    for n in range(0,10):
        file.write(str(Scores[n]) + "\n")
        file.write(Names[n]+ "\n")
        file.write(Dates[n]+ "\n")
    file.close()


    
        
def HighScore():
    #check score was greater than minimum high score
    global CurrentScore
    global Scores
    global Names
    global Dates
    global PlayerName
    global Ball
    global DisplayScreen
    temp = ""
    if int(CurrentScore) > int(Scores[9]):
        #at least a Daily high score.
        #Letter buttons so you can input Name
        for n in range(10):
            Lbl[n].grid_forget()
        for n in range(9): 
            btn[n].grid(row=1,column=n)
        btnBack.grid(row=1, column=9)
        for n in range(9,18): 
            btn[n].grid(row=2,column=n-9)
        for n in range(18,26): 
            btn[n].grid(row=3,column=n-18)
        btnSpace.grid(row=2, column=8)
        HighLabel.grid(row=0, column=0, columnspan=8)
        HighLabel1.grid(row=5, column=0, columnspan=8)
        HighLabel2.grid(row=6, column=0, columnspan=8)
        DisplayButton.set("Enter")
        #Set ball = "0" so that if the next button causes it to be displayed again
        #it won't trigger a high score check.  Also so it displays correctly as 0
        #instead of -1
        Ball="0"
        #LabelText[9].set("Ball = " + Ball)
        #set displayscreen value, so that when Next is pushed after entry of name
        #a the score will be displayed
        DisplayScreen=0
    else:
        #no high score so just display final score
        LabelText[1].set("Final Score = " + str(CurrentScore))
        LabelText[2].set("")
        LabelText[3].set("Rollovers = " + str(Rolls))
        LabelText[4].set("Pop Bumpers = " + str(Pops))
        LabelText[5].set("Targets = " + str(Targets))
        LabelText[6].set("")
        LabelText[7].set("")
        LabelText[8].set("")
        #Set ball = "0" so that if the next button causes it to be displayed again
        #it won't trigger a high score check.  Also so it displays correctly as 0
        #instead of -1
        Ball="0"
        LabelText[9].set("Ball = " + Ball)
        #set displayscreen value, so that when Next is pushed after entry of name
        #a the score will be displayed
        DisplayScreen=1

def sub(n):
    #get high score letters
    global PlayerName
    
    if n == -1:
        #Backspace pressed
        if len(PlayerName.get())!=0:
            PlayerName.set(PlayerName.get()[0:len(PlayerName.get())-1])
    else:
        # A letter was pressed so add it to the name
        temp = PlayerName.get() + chr(n+65)
        PlayerName.set(temp)
    
    
    
def DisplayScore(PinballData):
    global ScoreChecked
    global Pops
    global Rolls
    global Targets
    global CurrentScore
    global Ball
    global DisplayScreen
    #Hide start label
    StartLabel.grid_forget()
    
    # The serial data has the format    b'CurrentScore, Rolls, Pops, Targets\r\n'
    # convert data to text
    #print(PinballData)
    v = str(PinballData, 'utf-8')
    # v now has the format    CurrentScore, Rolls, Pops, Targets
    # break string into individual values
    FindString = ","
    Position = v.find(FindString)
    Position2 = v.find(FindString, Position + 1)
    Position3 = v.find(FindString, Position2 + 1)
    Position4 = v.find(FindString, Position3 + 1)
    CurrentScore = v[0:Position]
    Rolls=v[Position+2:Position2]
    Pops=v[Position2 + 2:Position3]
    Targets = v[Position3 + 2:Position4]
    Ball=v[Position4 +2 :len(v)-2]
    #Display Values
    #check if game over
    if Ball == "-1":
        #game just ended so check if a high score.
        HighScore()
    elif Ball == "0":
        #High score was already checked.
        #so just display score
        LabelText[1].set("Final Score = " + str(CurrentScore))
    else:
        LabelText[1].set("Current Score = " + str(CurrentScore))
        LabelText[2].set("")
        LabelText[3].set("Rollovers = " + str(Rolls))
        LabelText[4].set("Pop Bumpers = " + str(Pops))
        LabelText[5].set("Targets = " + str(Targets))
        LabelText[6].set("")
        LabelText[7].set("")
        LabelText[8].set("")
        LabelText[9].set("Ball = " + Ball)
        DisplayButton.set("Show High Scores")
    
    

def NextButton():
    # sub to handle Next button 
    global DisplayScreen
    global Scores
    global Names
    global DisplayScreen
    #Hide start label
    StartLabel.grid_forget()
    if DisplayScreen == 0:
        #A high score was achieved and a name should have been entered.
        SortScores()        
        #make labels visible again
        for n in range(10):
            Lbl[n].grid(row=n,column = 0, sticky=tk.W)
        #Hide labels used to enter name
        for n in range(26):
            btn[n].grid_forget()
            btnBack.grid_forget()
            btnSpace.grid_forget()
        HighLabel.grid_forget()
        HighLabel1.grid_forget()
        HighLabel2.grid_forget()
        DisplayScreen =1
    DisplayScreen = DisplayScreen + 1    
    if DisplayScreen == 4:
        DisplayScreen = 1
    if DisplayScreen == 1:
        #redisplay Scores
        if Ball == "0":
            LabelText[1].set("Final Score = " + str(format(int(CurrentScore), ",")))
        else:
            LabelText[1].set("Current Score = " + str(format(int(CurrentScore), ",")))
        LabelText[2].set("")
        LabelText[3].set("Rollovers = " + str(Rolls))
        LabelText[4].set("Pop Bumpers = " + str(Pops))
        LabelText[5].set("Targets = " + str(Targets))
        LabelText[6].set("")
        LabelText[7].set("")
        LabelText[8].set("")
        LabelText[9].set("Ball = " + Ball)
        DisplayButton.set("Show High Scores")
    elif DisplayScreen ==2:
        LabelText[1].set("All Time High Scores")
        LabelText[2].set("")
        #display scores as interger in comma format
        temp = format(int(Scores[0]), ",")
        LabelText[3].set(temp + " " * (10-len(temp))  + Names[0])
        temp = format(int(Scores[1]), ",")
        LabelText[4].set(temp + " " * (10-len(temp))  + Names[1])
        temp = format(int(Scores[2]), ",")
        LabelText[5].set(temp + " " * (10-len(temp))  + Names[2])
        temp = format(int(Scores[3]), ",")
        LabelText[6].set(temp + " " * (10-len(temp))  + Names[3])
        temp = format(int(Scores[4]), ",")
        LabelText[7].set(temp + " " * (10-len(temp))  + Names[4])
        LabelText[8].set("")
        LabelText[9].set("")
        DisplayButton.set("Show Today's High Scores")
    else:
        LabelText[1].set("Today's High Scores")
        LabelText[2].set("")
        temp = format(int(Scores[5]), ",")
        LabelText[3].set(temp + " " * (10-len(temp))  + Names[5])
        temp = format(int(Scores[6]), ",")
        LabelText[4].set(temp + " " * (10-len(temp))  + Names[6])
        temp = format(int(Scores[7]), ",")
        LabelText[5].set(temp + " " * (10-len(temp))  + Names[7])
        temp = format(int(Scores[8]), ",")
        LabelText[6].set(temp + " " * (10-len(temp))  + Names[8])
        temp = format(int(Scores[9]), ",")
        LabelText[7].set(temp + " " * (10-len(temp))  + Names[9])
        LabelText[8].set("")
        LabelText[9].set("")
        DisplayButton.set("Show Current Score")
    
    


def GetSerial():
    #115200
    #This is a separate thread that runs all the time
    #It constantly checks for info from the Arduino
    ser = serial.Serial('/dev/ttyACM0', 115200)
       
    while 1 :
        # get serial input
        #When it gets data, put in PinballData and update score.
        PinballData= ser.readline()
        DisplayScore(PinballData)
        


# Begin main program

root = tk.Tk()
# set default font. 
root.option_add("*Font", "Courier 24")
# Make full screen
root.attributes('-fullscreen', True)
# set up a frame 
frame = Frame(root)
frame.grid()
#set up variables for each label.  These will be changed to change display
for n in range(10):
    #temp = StringVar()
    LabelText.append(StringVar())
    Font = "Courier 28"
#Set up labels
for n in range(10):
    Lbl.append(Label(frame, textvariable=LabelText[n]))
    #grid statement must be on a separate line, since we will hide these labels later.
    Lbl[n].grid(row=n,column=0, sticky=tk.W)
# Set up display change button
DisplayButton = StringVar()
DisplayButton.set("Show High Scores")
bt=Button(root, textvariable=DisplayButton, command=NextButton,font = "Courier 20").grid(row=9, column=0, sticky=tk.W)
#Set up Buttons for Text entry for a high score.
for n in range(9): #create button matrix
    btn.append(Button(frame,text=str(chr(n+65)), command=lambda x=n: sub(x)))
btnBack=tk.Button(frame,text="BKS", command=lambda x=-1: sub(x))
for n in range(9,18): #create button matrix
    btn.append(Button(frame,text=str(chr(n+65)), command=lambda x=n: sub(x)))
for n in range(18,26): #create button matrix
    btn.append(Button(frame,text=str(chr(n+65)), command=lambda x=n: sub(x)))
btnSpace=tk.Button(frame,text=" ", command=lambda x=-33: sub(x))
btnSpace.grid(row=2, column=8)
PlayerName = StringVar()
PlayerName.set("")
HighLabel=Label(frame,text="High Score")
HighLabel.grid_forget
HighLabel1=Label(frame,text="Enter Name")
HighLabel1.grid_forget
HighLabel2=Label(frame,textvariable = PlayerName, bg="white")
HighLabel2.grid_forget

#hide all of the letter buttons until time to enter a high score
for n in range(26):
    btn[n].grid_forget()
btnBack.grid_forget()
btnSpace.grid_forget()
StartLabel=Label(frame, text ="Bob's Pinball")
StartLabel.grid(row=0,column=0)
# set up thread to get serial input independent of pushing 'Next' button
_thread.start_new_thread (GetSerial, DummyTuple )
root.mainloop()

Credits

Bob Blomquist

Bob Blomquist

3 projects • 33 followers
Chemist with computer programming skills.

Comments