I have a bokeh code that I open it with the terminal typing:
bokeh serve --show graph2d.py
how can I make a tkinter open this bokeh.py(graph2d.py)?
Please help with this, I dont find how to make it work.
this is the tkinter:
import tkinter as tk
from tkinter import *
import graph2d
"""import tkinter as Tk
from tkinter import ttk"""
window = Tk()
window.title("Welcome to PokerScatter app")
"""
WINDOW_SIZE = "600x400"
root = tk.Tk()
root.geometry(WINDOW_SIZE)
"""
selected = IntVar()
rad1 = Radiobutton(window,text='2d Scatter', value=1, variable=selected, command=graph2d)
rad2 = Radiobutton(window,text='3d Scatter', value=2, variable=selected)
rad3 = Radiobutton(window,text='Pie Chart', value=3, variable=selected)
rad4 = Radiobutton(window,text='Histogram', value=4, variable=selected)
def clicked():
print("Processing")
btn = Button(window, text="Show", command=clicked)
rad1.grid(column=0, row=0)
rad2.grid(column=2, row=0)
rad3.grid(column=0, row=1)
rad4.grid(column=2, row=1)
btn.grid(column=6, row=0)
window.mainloop()
Related
How can I make it so that when a certain window is active, the resolution is 1440x1080, but if any other window is active the resolution is 1920x1080 in Python?
(the comments are on purpose)
I'm using tkinter and I've tried:
import subprocess
import tkinter as tk
window = tk.Tk()
if tk.ACTIVE('notepad.exe') *res changing command*
else *res changing command*
# def setresEvent(event):
def startwinexpEvent(event):
subprocess.call(['C:\\Users\\VBucks\\Workspaces\\winexp\\winexp.exe'])
#setRes = tk.Button(
# text='Click me!',
# height=28,
# width=32,
# bg='black',
# fg='white',
#)
# setRes.bind('<Button-1>', setresEvent)
#setRes.pack()
startwinExp = tk.Button(
text='Start winexp',
height=28,
width=32,
bg='black',
fg='white',
)
startwinExp.bind('<Button-WinExp>', startwinexpEvent)
startwinExp.pack()
window.mainloop()
import tkinter
from tkinter import ttk
from tkinter import *
window = tkinter.Tk()
window.title("wasans")
window.geometry('640x400')
window.resizable(False, False)
textbook = ['국어','영어','social']
textbookselecter = ttk.Combobox(window, text="교과서 선택", values=textbook)
textbookselecter.grid(column=0, row=0)
textbookselecter.place(x=140, y=200)
textbookselecter.set("목록 선택")
textbooksuntack = ttk.Label(window, width=11, borderwidth=2, background="#8182b8")
textbooksuntack.grid(column=0, row=0)
textbooksuntack.place(x=170, y=170)
textbooksuntack.anchor = CENTER
naeyong = textbookselecter.get()
if naeyong == "social":
open("../social.py", "w")
window.mainloop()
How can I open a py file using if statement and open?
Also, please give your overall review of the code.
I am not good at English, so there may be awkward sentences using a translator. Please understand.
You basically need to check every time the ttk.Combobox is changed to check if 'social' is generated.
ttk.Combobox raises a "<<ComboboxSelected>>" virtual event when selected.
import tkinter
from tkinter import ttk
from tkinter import *
window = tkinter.Tk()
window.title("wasans")
window.geometry('640x400')
window.resizable(False, False)
def callback(eventObject):
if textbookselecter.get() == "social":
print("Opening File...")
#file=open("...../social.py","r+")
textbook = ['국어','영어','social']
textbookselecter = ttk.Combobox(window, text="교과서 선택", values=textbook)
textbookselecter.grid(column=0, row=0)
textbookselecter.place(x=140, y=200)
textbookselecter.set("목록 선택")
textbooksuntack = ttk.Label(window, width=11, borderwidth=2, background="#8182b8")
textbooksuntack.grid(column=0, row=0)
textbooksuntack.place(x=170, y=170)
textbooksuntack.anchor = CENTER
textbookselecter.bind("<<ComboboxSelected>>",callback)
window.mainloop()
So till now I want to make a simple button but it gives me an error screen, what am I doing wrong? Here's my code:
import tkinter as tk
import math
import time
tk = tk.Tk()
tk.geometry()
tk.attributes("-fullscreen", True)
exit_button = tk.Button(tk, text = "Exit", height = 2, width = 2, command = tk.destroy)
exit_button.place(x=1506, y=0)
tk.mainloop()
You are shadowing tk with something else:
import tkinter as tk
root = tk.Tk()
root.geometry()
root.attributes("-fullscreen", True)
exit_button = tk.Button(root, text="Exit", height=2, width=2, command=root.destroy)
exit_button.place(x=1506, y=0)
tk.mainloop()
You cannot use tk = tk.Tk(), because you are also referring to tkinter as tk. So either:
Change your imports(not recommended):
import tkinter as _tk
tk = _tk.Tk() # And so on..
or change your variable name(recommended):
root = tk.Tk() # And change tk.geometry to root.geometry() and so on
I made a form in Tkinter but when it is anwered I need the information to concatenate to a textbox.
Let's say I select I live in Chicago, how do I send that information to the scrolled text when I press the button "send"?
lblCd= Label(ventana,text="Location:",font= ("Arial", 20),
fg="blue", bg="white").place(x=70,y=400)
combo['values']=("Chicago","NY", "Texas")
combo.current(1)
combo.place(x=260, y=400)
Btn=Button(ventana, text="Send",)
Btn.place(x=200,y=500)
txt=scrolledtext.ScrolledText(ventana, width=40, height=10)
txt.place(x=260, y= 550)
txt.insert(INSERT, Nombre)
You can use Button(..., command=function_name) to execute function_name() when you press button. This function can get selected value and insert in scrolledtext.
import tkinter as tk
import tkinter.ttk as ttk
import tkinter.scrolledtext as scrolledtext
def send_data():
txt.insert('end', combo.get() + '\n')
root = tk.Tk()
label = tk.Label(root, text="Location:")
label.pack()
combo = ttk.Combobox(root, values=("Chicago","NY", "Texas"))
combo.pack()
combo.current(0)
button = tk.Button(root, text="Send", command=send_data)
button.pack()
txt = scrolledtext.ScrolledText(root)
txt.pack()
root.mainloop()
I have created an coding gui,which doesnot show 'File' and 'save' in the Gui
Please help me to fix my problem.
I have created a Function for File and Save ,still not working!
please help me to rectify my code!
from tkinter import *
import tkinter.messagebox
import tkinter
import tkinter as tki
import tkinter.filedialog as th1
import re
class App(object):
def __init__(self,root):
self.root = root
# create a Frame for the Text and Scrollbar
txt_frm = tki.Frame(self.root, width=600, height=400)
txt_frm.pack(fill="both", expand=True)
# ensure a consistent GUI size
txt_frm.grid_propagate(False)
# create first Text label, widget and scrollbar
self.lbl1 = tki.Label(txt_frm, text="Type")
self.lbl1.grid(row=0,column=0,padx=2,pady=2)
self.txt1 = tki.Text(txt_frm, borderwidth=3, relief="sunken", height=4,width=55)
self.txt1.config(font=("consolas", 12), undo=True, wrap='word')
self.txt1.grid(row=0, column=1, sticky="nsew", padx=2, pady=2)
scrollb1 = tki.Scrollbar(txt_frm, command=self.txt1.yview)
scrollb1.grid(row=0, column=2, sticky='nsew')
self.txt1['yscrollcommand'] = scrollb1.set
button = tki.Button(txt_frm,text="Clickone", command = self.retrieve_input)
button.grid(column=2,row=0)
button1 = tki.Button(txt_frm,text="Cli", command = self.clearBox)
button1.grid(column=2,row=0)
def retrieve_input(self):
input1 = self.txt1.get("0.0",'end-1c')
with open('text.txt','a+') as f:
f.write(input1+'\n')
f.close()
def clearBox(self):
self.txt1.delete('1.0', 'end')#<-0.0/1.0
def file_save():
f = th1.asksaveasfile(mode='w', defaultextension=".txt")
if f is None: # asksaveasfile return `None` if dialog closed with "cancel".
return
text2save = str(text.get(1.0, END))
a= (f)
f.write(text2save)
f.close()
root = tki.Tk()
menubar=Menu(root)
filemenu=Menu(menubar,tearoff=0)
filemenu.add_command(label="Save", command=file_save)
app = App(root)
root.mainloop()
Please help!Answers will be appreciated!
You aren't adding the menubar to the window. Add this after you create the menubar.
root.configure(menu=menubar)
You then also have to add the file menu to the menubar:
menubar.add_cascade(label="File", menu=filemenu)