Skip to content

Instantly share code, notes, and snippets.

@secemp9
Created May 30, 2024 16:04
Show Gist options
  • Save secemp9/65055388ea8d06c67a3a4f3a662dde19 to your computer and use it in GitHub Desktop.
Save secemp9/65055388ea8d06c67a3a4f3a662dde19 to your computer and use it in GitHub Desktop.
Tkinter request, twitter
import tkinter as tk
def send_message(event=None):
message = input_entry.get()
if message.strip():
chat_history.configure(state=tk.NORMAL)
chat_history.insert(tk.END, "You: " + message + "\n")
chat_history.configure(state=tk.DISABLED)
input_entry.delete(0, tk.END)
# TODO: Send the message to the backend and receive the response
response = send_to_backend(message)
# Display the received response
chat_history.configure(state=tk.NORMAL)
chat_history.insert(tk.END, "Output: " + response + "\n")
chat_history.configure(state=tk.DISABLED)
chat_history.see(tk.END)
def send_to_backend(message):
# Placeholder for backend communication
return "This is a response"
# Create the main window
window = tk.Tk()
window.title("Chat Window")
# Set the minimum size for the window
window.minsize(400, 300)
# Create a frame to hold the chat history and input entry
main_frame = tk.Frame(window)
main_frame.pack(fill=tk.BOTH, expand=True)
# Configure the grid of the main frame
main_frame.grid_rowconfigure(0, weight=1)
main_frame.grid_columnconfigure(0, weight=1)
# Create the chat history frame
chat_frame = tk.Frame(main_frame)
chat_frame.grid(row=0, column=0, sticky="nsew")
# Create the chat history text area
chat_history = tk.Text(chat_frame, bg="black", fg="white", font=("Arial", 12), state=tk.DISABLED)
chat_history.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
# Create the input entry frame
input_frame = tk.Frame(main_frame)
input_frame.grid(row=1, column=0, sticky="ew")
# Create the input entry box
input_entry = tk.Entry(input_frame, font=("Arial", 12))
input_entry.pack(fill=tk.X, padx=5, pady=5)
input_entry.bind("<Return>", send_message)
# Allow the window to be resizable
window.resizable(True, True)
# Start the GUI event loop
window.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment