Skip to content

Instantly share code, notes, and snippets.

View ceffiong's full-sized avatar

ceffiong

View GitHub Profile
@ceffiong
ceffiong / tkmain.py
Last active February 6, 2020 11:45
Guessing Game Main Window
import tkinter as tk
window = tk.Tk()
window.title("Guessing Game")
lblInst = tk.Label(window, text = "Guess a number from 0 to 9")
lblLine0 = tk.Label(window, text = "*********************************************************************")
# append elements to grid
lblInst.grid(row=0, column=0, columnspan=5)
@ceffiong
ceffiong / tkAllComponents.py
Created February 6, 2020 12:03
Main Game window with all Widgets added
import tkinter as tk
window = tk.Tk()
window.title("Guessing Game")
lblInst = tk.Label(window, text = "Guess a number from 0 to 9")
lblLine0 = tk.Label(window, text = "*********************************************************************")
lblNoGuess = tk.Label(window, text = "No of Guesses: 0")
lblMaxGuess = tk.Label(window, text = "Max Guess: 3")
lblLine1 = tk.Label(window, text = "*********************************************************************")
@ceffiong
ceffiong / tkmainAll.py
Created February 6, 2020 13:43
Guessing game with python and tk library all source codes
import tkinter as tk
from random import randrange
window = tk.Tk()
window.title("Guessing Game")
lblInst = tk.Label(window, text = "Guess a number from 0 to 9")
lblLine0 = tk.Label(window, text = "*********************************************************************")
lblNoGuess = tk.Label(window, text = "No of Guesses: 0")
lblMaxGuess = tk.Label(window, text = "Max Guess: 3")
@ceffiong
ceffiong / server_gui.py
Created February 13, 2020 13:09
Multi-user Group Chat Server GUI
import tkinter as tk
window = tk.Tk()
window.title("Sever")
# Top frame consisting of two buttons widgets (i.e. btnStart, btnStop)
topFrame = tk.Frame(window)
btnStart = tk.Button(topFrame, text="Connect", command=lambda : start_server())
btnStart.pack(side=tk.LEFT)
btnStop = tk.Button(topFrame, text="Stop", command=lambda : stop_server(), state=tk.DISABLED)
btnStop.pack(side=tk.LEFT)
@ceffiong
ceffiong / server_logic.py
Created February 13, 2020 13:50
Multi-user Group Chat Server Logic
import tkinter as tk
import socket
import threading
window = tk.Tk()
window.title("Sever")
# Top frame consisting of two buttons widgets (i.e. btnStart, btnStop)
topFrame = tk.Frame(window)
import socket
import threading
##### GUI component omitted #######
### See https://gist.github.com/effiongcharles/9d0d4fa3163b3350f1399902058fb9ae.js for preceeing source codes
server = None
HOST_ADDR = "0.0.0.0"
HOST_PORT = 8080
client_name = " "
@ceffiong
ceffiong / server_accept_clients.py
Created February 13, 2020 16:06
Multi-user Group Chat Server function to accept clients
### several lines of codes ommitted
### See https://gist.github.com/effiongcharles/290854dba0f1bea7a609138cd9efcd65.js for preceeing codes
def accept_clients(the_server, y):
while True:
client, addr = the_server.accept()
clients.append(client)
# use a thread so as not to clog the gui thread
threading._start_new_thread(send_receive_client_message, (client, addr))
@ceffiong
ceffiong / server_send_receive_client_message.py
Last active February 15, 2020 20:31
Multi-user Group Chat Server function to send and receive clients messages
### several lines of codes ommitted
### See https://gist.github.com/effiongcharles/4976708e0791cfc959953743e4650b5e.js for preceeing codes
# Function to receive message from current client AND
# Send that message to other clients
def send_receive_client_message(client_connection, client_ip_addr):
global server, client_name, clients, clients_addr
client_msg = " "
# send welcome message to client
@ceffiong
ceffiong / client_gui.py
Last active February 15, 2020 21:18
Client user interface
import tkinter as tk
from tkinter import messagebox
window = tk.Tk()
window.title("Client")
username = " "
topFrame = tk.Frame(window)
lblName = tk.Label(topFrame, text = "Name:").pack(side=tk.LEFT)
entName = tk.Entry(topFrame)
@ceffiong
ceffiong / client_connect_to_server.py
Last active February 15, 2020 21:23
Client application - connect to server method
# Note: several lines of codes omitted.
# For previous codes see: https://gist.github.com/effiongcharles/de4b7622591b5f414ab814733fe6ff02.js
client = None
HOST_ADDR = "0.0.0.0"
HOST_PORT = 8080
def connect_to_server(name):
global client, HOST_PORT, HOST_ADDR
try: