`tkinter.iconbitmap` method returns empty string
I have an app:
class App(tk.Tk): def __init__(self): super().__init__() # Set app title self.app_title = 'Visual Python' self.title(self.app_title) # Set app icon self.iconbitmap('icon.ico')
And a test:
class TestApp(unittest.TestCase): def setUp(self): self.app = App() def test_app_title(self): self.assertEqual(self.app.title(), 'Visual Python') def test_app_icon(self): self.assertEqual(self.app.iconbitmap(), 'icon.ico')
When I ran the test with
py -3 -m unittest, I get this output:
F. ====================================================================== FAIL: test_app_icon (test.test_app.TestApp) ---------------------------------------------------------------------- Traceback (most recent call last): File "C:\Users\ismailarilik\visual-python\test\test_app.py", line 12, in test_app_icon self.assertEqual(self.app.iconbitmap(), 'icon.ico') AssertionError: '' != 'icon.ico' + icon.ico ---------------------------------------------------------------------- Ran 2 tests in 0.279s FAILED (failures=1)
iconbitmap method here return an empty string instead of the given
If an empty string is specified for bitmap, then any current icon bitmap is cancelled for window. If bitmap is specified then the command returns an empty string. Otherwise it returns the name of the current icon bitmap associated with window, or an empty string if window has no icon bitmap.
I think your situation falls into the last case highlighted in bold text. I mean you have to be sure the icon is set correctly, depending on your platform.
See also questions close to this topic
Keras Lambda Layer Before Embedding: Use to Convert Text to Integers
I currently have a
kerasmodel which uses an
Embeddinglayer. Something like this:
input = tf.keras.layers.Input(shape=(20,) dtype='int32') x = tf.keras.layers.Embedding(input_dim=1000, output_dim=50, input_length=20, trainable=True, embeddings_initializer='glorot_uniform', mask_zero=False)(input)
This is great and works as expected. However, I want to be able to send text to my model, have it preprocess the text into integers, and continue normally.
1) The Keras docs say that Embedding layers can only be used as the first layer in a model: https://keras.io/layers/embeddings/
2) Even if I could add a
Lambdalayer before the
Embedding, I'd need it to keep track of certain state (like a dictionary mapping specific words to integers). How might I go about this stateful preprocessing?
In short, I need to modify the underlying Tensorflow DAG, so when I save my model and upload to ML Engine, it'll be able to handle my sending it raw text.
PySpark: Sort or OrderBy DataFrame Column *Numerically* not working correctly
I have some fitness data that I'm trying to sort numerically, however the results are not turning out as the manual, and other examples, e.g. Spark DataFrame groupBy and sort in the descending order (pyspark), show:
display(df.sort(col("Calories Burned").desc()))#fails to sort correctly, shows 876, then 4756, display(df.orderBy("Calories Burned", ascending = False))#fails to sort correctly, shows 876, then 4756 display(df.sort(desc("Calories Burned")))
All these examples display the following two columns data (there are more columns, but I'm abbreviating for space):
Date Calories Burned 2018-10-18 876 2018-05-26 4756 2018-05-05 4440
As you can see, these are not sorting numerically. Spark isn't taking the number of digits into account, so 876 appears before 4756.
Whether or not I include the
colfunction makes no difference, either.
How can this dataset be sorted numerically so the data looks more like this?
Date Calories Burned 2018-05-26 4756 2018-05-05 4440 2018-10-18 876
Turtle is not reacting to onkeypress [SOLVED]
So, I am new in python so I took some time and watched some videos about how to make a simple "snake" game, I was doing everything that dude was saying, but when it came to the keyboard binding something went wrong and I can't move my turtle..
import turtle import time delay = 0.1 # Screen wn = turtle.Screen() wn.title("Snake Game By AniPita") wn.bgcolor('black') wn.setup(600, 600) wn.tracer(0) # Snake Head head = turtle.Turtle() head.speed(0) head.shape("square") head.color("white") head.penup() head.goto(0, 0) head.direction = "stop" # Functions def go_up(): head.direction == "up" def go_down(): head.direction == "down" def go_left(): head.direction == "left" def go_right(): head.direction == "right" def move(): if head.direction == "up": y = head.ycor() head.sety(y + 10) if head.direction == "down": y = head.ycor() head.sety(y - 10) if head.direction == "left": x = head.xcor() head.setx(x - 10) if head.direction == "right": x = head.xcor() head.setx(x + 10) # Keyboard Bindings wn.onkeypress(go_up(), 'w') wn.onkeypress(go_down(), 's') wn.onkeypress(go_left(), 'a') wn.onkeypress(go_right(), 'd') wn.listen() # Main Game while True: wn.update() time.sleep(delay) move() wn.mainloop()
How do I write Jasmine unit tests for an AngularJS application that will eventually be upgraded to Angular 6?
So I have an AngularJS application that is going to be upgraded to Angular 6 very soon. However, the current AngularJS application has zero unit tests. Since I am tasked with doing the upgrade, I want to make sure that I have equal functionality between the legacy app and the eventual Angular 6 version, and my plan to do that is to use unit tests to ensure this.
This comes with unique problems. For example, controllers are no longer a thing along with $scope and $rootScope in Angular 2+, but I need to write unit tests for the existing controllers since none currently exist. However, if I spend the time and write the unit tests for the controller, those tests will very shortly be obsolete and useless.
Is the best way to simply write the tests for the AngularJS application, and then write a second version of those same unit tests, but for the Angular 6 components? Or is there another way I do not know of?
The current AngularJS version used by the application is 1.3.x, and the plan is to upgrade to Angular 6/7. The latest version of Karma and Jasmine are also being used.
Thanks in advance.
Mock PHP md5 function with Mockery
I would like to know how can I mock the PHP md5 function with Mockery?
I'm looking for something like this:
Kafka GroupTable tests generating extra messages when using ProcessorTopologyTestDriver
I've written a stream that takes in messages and sends out a table of the keys that have appeared. If something appears, it will show a count of 1. This is a simplified version of my production code in order to demonstrate the bug. In a live run, a message is sent out for each message received.
However, when I run it in a unit test using ProcessorTopologyTestDriver, I get a different behavior. If a key that has already been seen before is received, I get an extra message.
If I send messages with keys "key1", then "key2", then "key1", I get the following output.
key1 - 1 key2 - 1 key1 - 0 key1 - 1
For some reason, it decrements the value before adding it back in. This only happens when using ProcessorTopologyTestDriver. Is this expected? Is there a work around? Or is this a bug?
Here's my topology:
final StreamsBuilder builder = new StreamsBuilder(); KGroupedTable<String, String> groupedTable = builder.table(applicationConfig.sourceTopic(), Consumed.with(Serdes.String(), Serdes.String())) .groupBy((key, value) -> KeyValue.pair(key, value), Serialized.with(Serdes.String(), Serdes.String())); KTable<String, Long> countTable = groupedTable.count(); KStream<String, Long> countTableAsStream = countTable.toStream(); countTableAsStream.to(applicationConfig.outputTopic(), Produced.with(Serdes.String(), Serdes.Long()));
Here's my unit test code:
TopologyWithGroupedTable top = new TopologyWithGroupedTable(appConfig, map); Topology topology = top.get(); ProcessorTopologyTestDriver driver = new ProcessorTopologyTestDriver(config, topology); driver.process(inputTopic, "key1", "theval", Serdes.String().serializer(), Serdes.String().serializer()); driver.process(inputTopic, "key2", "theval", Serdes.String().serializer(), Serdes.String().serializer()); driver.process(inputTopic, "key1", "theval", Serdes.String().serializer(), Serdes.String().serializer()); ProducerRecord<String, Long> outputRecord = driver.readOutput(outputTopic, keyDeserializer, valueDeserializer); assertEquals("key1", outputRecord.key()); assertEquals(Long.valueOf(1L), outputRecord.value()); outputRecord = driver.readOutput(outputTopic, keyDeserializer, valueDeserializer); assertEquals("key2", outputRecord.key()); assertEquals(Long.valueOf(1L), outputRecord.value()); outputRecord = driver.readOutput(outputTopic, keyDeserializer, valueDeserializer); assertEquals("key1", outputRecord.key()); assertEquals(Long.valueOf(1L), outputRecord.value()); //this fails, I get 0. If I pull another message, it shows key1 with a count of 1
Here's a repo of the full code:
Tkinter module - program will just run then stop and won't open the window
I need help, I am doing a budget calculator and using
tkinterfor the first time and wondered why it is not working...
When I run it, it will just end straight away and when I put the
root = Tk()at the end it comes up with an error.
I really need help, my code is below...
from time import sleep from tkinter import * from tkinter import messagebox, ttk, Tk root = Tk() class GUI(): def taskbar(self): menu = Menu() file = Menu(menu) file.add_command(label="Exit", command=self.exit_GUI) file.add_command(label = "Information", command=self.info_popup) def Main_Menu(self): topFrame = Frame(root) topFrame.pack() bottomFrame = Frame(root) bottomFrame.pack(side=BOTTOM) Income_button = Button(topFrame, text="Enter your incomes", command=self.Income) Expense_button = Button(topFrame, text="Enter your expenses", command=self.Expense) Total_button = Button(bottomFrame, text="View Results", command=self.Total) Income_button.pack() Expense_button.pack() Total_button.pack() def Income(self): pass def Expense(self): pass def Total(self): pass def exit_GUI(self): exit() def info_popup(): pass g = GUI() g.Main_Menu() g.taskbar() g.Income() g.Expense() g.Total() g.exit_GUI() g.info_popup() root.mainloop()
Getting NameError trying to access my tkinter widget in my button command function
I wrote a class for my tkinter GUI and for some reason I can't access the
Entrywidget I created in my button's callback function:
import tkinter as tk class MyGUI: def __init__(self, master): entry = tk.Entry(master) entry.pack() self.run = tk.Button(master, text="Run", command=self.run) self.run.pack() def run(self): print('Entry content is:', entry.get()) root = tk.Tk() my_gui = MyGUI(root) root.mainloop()
The code throws
NameError: name 'entry' is not defined. What am I doing wrong?
Tkinter GUI implemented with Separate Python file with functions
I am having problem with having a GUI interface to be implemented via a second file which just contains the file to read, plots made and some new functions to be evaluated based on that.
I am trying to create a GUI application using Tkinter. The way I am doing is as follows. I have a background script (say Background.py) which has two functions. Function X loads a data file, does some calculations and outputs a graph. The way I want to trigger this is via a GUI script in another file (GUI.py) which opens a panel with a button and when I click the button the function X in file Background.py should be evaluated and a plot should be shown. Once I check the plot, I can hit another button to close the plot and terminate the function X. Now I can choose to click another button to trigger the function Y in the file Background.py. These button should allow me to input three values, which should be the input to the function Y in the file Background.py. Once I hit this button, it should trigger the function Y and do what it it asks it to do. Now at the end, after that I can hit the button to close the gui.
How can I do this?. A general rough idea will be helpful.
I have put an example as much as I can:( at least the skeleton of the code) I have a background file say (Background.py) and gui file ( say GUI.py)
import numpy import matplotlib.pyplot as plt import pandas def progX(): df = pd.read (myfile) ##df.stats # doing something and generating a plot from the file plt.boxplot(df['col']) plt.show() def progY(y1, y2,y3): ## get the y1, y2, y3 from the GUI interface which the user has entered #run a code... and generate an output file
import Background as bg from tkinter import * from tkinter.ttk import * class GUI (): def create widgets(self): #.... def create_panel2(self): #create buttons panel1 = ... btn1 = Button(panel1, text="yyyyy", command=bg.progA) btn1.pack() def create_panel2(self): #create buttons panel2 = ... btn2 = Button(panel1, text="yyyyy", command=bg.progB) btn2.pack() All_Entries =  window = Tk() D=GUI(window) window.mainloop() runprogram1 = bg.progX() runprogram2 = bg.probY(x, y, z)
My question is now, does the above makes sense? How can I call the background functions from the GUI? The statements runprogram1 & runprogram2 are definitely not correct, How can I implement that. Also how will I ensure that I call the proram Y in Background once I have close the output from the program X?
I guess the questions makes sense. I am new to GUI and having hard time working this out, which I need to. any help will be very much appreciated.