Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| #Globals | |
| legal_numbers = [1,2,3,4,5,6,7,8,9] | |
| col1, col2, col3 = st.columns(3) | |
| col4, col5, col6 = st.columns(3) | |
| col7, col8, col9 = st.columns(3) | |
| def get_userInput(): | |
| input = st.text_input("Enter a number between 1 to 9: ", key="input") | |
| st.text("Legal Numbers: " + "".join(str(legal_numbers))) | |
| return input | |
| def validate_userInput(user_input): | |
| if user_input.isdigit(): | |
| return True | |
| else: | |
| return "Please enter a digit between 1 to 9." | |
| def display_board(): | |
| with col1: | |
| st.text("X") | |
| with col2: | |
| st.text("O") | |
| with col3: | |
| st.text("...") | |
| with col4: | |
| st.text(" X ") | |
| with col5: | |
| st.text(" O ") | |
| with col6: | |
| st.text(" ... ") | |
| with col7: | |
| st.text(" X ") | |
| with col8: | |
| st.text(" O ") | |
| with col9: | |
| st.text(" ... ") | |
| def reset_legalNumbers(): | |
| legal_numbers = [1,2,3,4,5,6,7,8,9] | |
| #def update_legalNumbers(): | |
| #UIApp starts here | |
| st.set_page_config(page_title="Python - Tic Tac Toe", page_icon=":python:") | |
| st.header("Python - Tic Tac Toe") | |
| user_input=get_userInput() | |
| display_board() | |
| #UI Buttons | |
| submit=st.button('Submit') | |
| replay=st.button('Replay') | |
| #After User Interaction | |
| response=validate_userInput(user_input) | |
| #Button functionality | |
| if submit: | |
| st.subheader("") | |
| st.write(response) | |
| if replay: | |
| display_board() |